Open In App

HTML DOM Script src Property

The DOM Script src Property is used to set or return the value of the src attribute of an <script> element. The src attribute specifies the URL of the External Javascript file. 

Syntax: 



scriptObject.src
scriptObject.src = URL

Property Values: It contains the value i.e. URL which specifies the URL of the External Javascript File. 

Two Types of URLs: 



Return Value: It returns a string value that represents the URL of the External Javascript File. 

Example: This Example returns the src Property. 




<!DOCTYPE html>
<html>
 
<head>
    <title>
        DOM script src Property
    </title>
</head>
 
<body style="text-align:center;">
    <h1>
        GeeksForGeeks
    </h1>
 
    <h2>
        DOM script src property
    </h2>
 
    <script id="myGeeks"
            type="text/javascript"
            src="my_script.js">
    </script>
    <br>
    <button onclick="Geeks()">
          Submit
      </button>
    <h2 id="demo"></h2>
   
    <script>
        function Geeks() {
            let x = document.getElementById(
                "myGeeks").src;
            document.getElementById(
                "demo").innerHTML = x;
        }
    </script>
 
</body>
 
</html>

Output:

 

Supported Browsers: The browsers supported by HTML DOM Script src Property are listed below:


Article Tags :