Script src Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Script

Description

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

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

Set the src property with the following Values

Value Description
URL The URL of the external script file.

Return Value

A String, representing the URL of the external script file.

The following code shows how to get the URL of an external script file:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

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

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

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

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

</body>
</html>

Related Tutorials