Javascript examples for DOM:Document scripts
Document scripts Collection namedItem(id) - Get the contents of the <script> element with id="myScript" in the document:
<!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>