YouTip LogoYouTip

Prop Script Text

HTML DOM Script text Property

HTML DOM Script text Property

Script text Property

Example

Get the content of the <script> element:

var x = document.getElementById("myScript").text

x output:

document.write("Hello World!");

Try it Yourself Β»


Definition and Usage

The text property sets or returns the content of the <script> element.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The text property is supported in all major browsers.


Syntax

Return the text property:

scriptObject.text

Set the text property:

scriptObject.text=contents

Property Values

Value Description
contents Specifies the content of the script.

Technical Details

Return Value: A String, representing the content of the script. Returns the content of all child text nodes of the <script> element (other nodes, like comments or elements, are ignored).

More Examples

Example

Another example - Get the content of the <script> element:

var x = document.getElementById("myScript").text

x output:

var fruits = ["Banana", "Orange", "Apple", "Mango"];
function fruitFunction() {
    fruits.pop();
    var x = document.getElementById("fruitdemo");
    x.innerHTML=fruits;
}

Try it Yourself Β»

← Prop Script TypeProp Script Src β†’