Latest web development tutorials
 

Script text Property

Script Object Reference 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

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 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 Reference Script Object