Javascript DOM HTML Script src Property get

Introduction

Get the URL of an external script file:

var x = document.getElementById("myScript").src

Click the button to get the URL of the external script file.

View in separate window

<!DOCTYPE html>
<html>
<body>

<script id="myScript" src="javascript.js"></script>
<button onclick="myFunction()">Test</button>

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

<script>
function myFunction() {// ww w .  jav a2 s .c om
  var x = document.getElementById("myScript").src;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The src property sets or gets the value of the src attribute of a script.

The src attribute specifies the URL of an external script file.

The src property accepts and returns a String type value.




PreviousNext

Related