Document scripts Collection namedItem(id) - Get the contents of the <script> element with id="myScript" in the document: - Javascript DOM

Javascript examples for DOM:Document scripts

Description

Document scripts Collection namedItem(id) - Get the contents of the <script> element with id="myScript" in the document:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<script>
document.write("Hello World!");
</script>/*from w ww. j a  va2s .c o  m*/

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script id="myScript">
function myFunction() {
    var x = document.scripts.namedItem("myScript").text;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

Related Tutorials