Get Script Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Script

Introduction

The Script object represents an HTML <script> element.

You can access a <script> element by using getElementById():

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<script id="myScript" src="src.js"></script>

<button onclick="myFunction()">get the URL of the external script file</button>

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

<script>
function myFunction() {//from   www .ja  v  a  2 s.c o  m
    var x = document.getElementById("myScript").src;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

Related Tutorials