Script text Property - how to get the contents of the <script> element: - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Script

Description

Script text Property - 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() {/* w w w .jav a  2s  .  c om*/
    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