<!DOCTYPE html>
<html>
<body>
<script>
document.write("Hello World!");
</script>
<p>Click the button to get the contents of the first script element in the document.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.scripts.item(0).text;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>