<!DOCTYPE html>
<html>
<body>
<script>
document.write("Hello World!");
</script>
<p>Click the button to get the contents of the script element with id="myScript".</p>
<button onclick="myFunction()">Try it</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>