The src
attribute specifies the URL of an external script file.
The src
property sets or gets the src attribute of a script.
src |
Yes | Yes | Yes | Yes | Yes |
Return the src property.
var v = scriptObject.src
Set the src property.
scriptObject.src=URL
Value | Description |
---|---|
URL | The URL of the external script file. |
Possible values.
A String type value representing the URL of the external script file.
The following code shows how to get the URL of an external script file.
<!DOCTYPE html>
<html>
<body>
<script id="myScript" src="my.js"></script>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {<!-- w w w . j a v a 2 s .c o m-->
var x = document.getElementById("myScript").src;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows: