Document scripts Collection item(index) - Get the contents of the first <script> element (index 0) in the document: - Javascript DOM

Javascript examples for DOM:Document scripts

Description

Document scripts Collection item(index) - Get the contents of the first <script> element (index 0) in the document:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<script>
document.write("Hello World!");
</script>//from  w  w w .j  a  va 2  s .  c o  m

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

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

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

</body>
</html>

Related Tutorials