Javascript Reference - HTML DOM Script src Property








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

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

Browser Support

src Yes Yes Yes Yes Yes

Syntax

Return the src property.

var v = scriptObject.src 

Set the src property.

scriptObject.src=URL




Property Values

Value Description
URL The URL of the external script file.

Possible values.

Return Value

A String type value representing the URL of the external script file.

Example

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: