THE WORLD'S LARGEST WEB DEVELOPER SITE

Script text Property

❮ Script Object

Example

Get the contents of the <script> element:

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

The result of x will be:

document.write("Hello World!");
Try it Yourself »

Definition and Usage

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


Browser Support

Property
text Yes Yes Yes Yes Yes

Syntax

Return the text property:

scriptObject.text

Set the text property:

scriptObject.text=contents

Property Values

Value Description
contents Specifies the contents of the script

Technical Details

Return Value: A String, representing the contents of the script. Returns all the text nodes that are children of the <script> element in tree order (other nodes, like comments or elements will be ignored).

More Examples

Example

Another example of how to get the contents of the <script> element:

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

The result of x will be:

var fruits = ["Banana", "Orange", "Apple", "Mango"]; function fruitFunction() { fruits.pop(); var x = document.getElementById("fruitdemo"); x.innerHTML=fruits; }
Try it Yourself »
❮ Script Object