X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY ANGULAR BOOTSTRAP XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

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

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB HOSTING

UK Reseller Hosting

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE

facebook