Javascript examples for DOM HTML Element:Script
The text property sets or gets the contents of the <script> element.
Set the text property with the following Values
Value | Description |
---|---|
contents | Sets the contents of the script |
A String, representing the contents of the script.
Returns all the text nodes that are children of the <script> element in tree order.
The following code shows how to get the contents of the <script> element:
<!DOCTYPE html> <html> <body> <p id="fruitdemo"></p> <button onclick="fruitFunction()">Remove the last array</button> <script id="myScript"> var fruits = ["A", "B", "C", "D"]; function fruitFunction() {//from ww w. j a v a 2s.c o m fruits.pop(); var x = document.getElementById("fruitdemo"); x.innerHTML = fruits; } </script> <p id="contentsdemo"></p> <button onclick="textFunction()">Return contents</button> <script> function textFunction() { var x = document.getElementById("myScript").text; document.getElementById("contentsdemo").innerHTML = x; } </script> </body> </html>