Script text Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Script

Description

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

Set the text property with the following Values

ValueDescription
contents Sets the contents of the script

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.

The following code shows how to get the contents of the <script> element:

Demo Code

ResultView the demo in separate window

<!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>

Related Tutorials