HTML DOM Script text Property
JavaScript Reference
Script text Property
Example
Get the content of the <script> element:
var x = document.getElementById("myScript").text
x output:
document.write("Hello World!");
Definition and Usage
The text property sets or returns the content of the <script> element.
Browser Support
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;
}
YouTip