HTML DOM Script src Attribute
-- Learning is not just about technology, but also about dreams!
- Home
- HTML
- JavaScript
- CSS
- Vue
- React
- Python3
- Java
- C
- C++
- C#
- AI
- Go
- SQL
- Linux
- VS Code
- Bootstrap
- Git
- Local Bookmarks
JavaScript Reference
JavaScript Objects
- JavaScript Array Object
- JavaScript Boolean Object
- JavaScript Date Object
- JavaScript Math Object
- JavaScript Number Object
- JavaScript String Object
- JavaScript RegExp Object
- JavaScript Global Properties/Functions
- JavaScript Operators
- JavaScript Error
Browser Objects
DOM Objects
- HTML DOM Document Object
- HTML DOM Element Object
- HTML DOM Attribute Object
- HTML DOM Event Object
- HTML DOM Console Object
- CSSStyleDeclaration Object
- DOM HTMLCollection
HTML Objects
- <a>
- <area>
- <audio>
- <base>
- <blockquote>
- <body>
- <button>
- <canvas>
- <col>
- <colgroup>
- <datalist>
- <del>
- <details>
- <dialog>
- <embed>
- <fieldset>
- <form>
- <iframe>
- <frameset >
- <img>
- <ins>
- <input> - button
- <input> - checkbox
- <input> - color
- <input> - date
- <input> - datetime
- <input> - datetime-local
- <input> - email
- <input> - file
- <input> - hidden
- <input> - image
- <input> - month
- <input> - number
- <input> - range
- <input> - password
- <input> - radio
- <input> - reset
- <input> - search
- <input> - submit
- <input> - text
- <input> - time
- <input> - url
- <input> - week
- <keygen>
- <link>
- <label>
- <legend>
- <li>
- <map>
- <menu>
- <menuItem>
- <meta>
- <meter>
- <object>
- <ol>
- <optgroup>
- <option>
- <param>
- <progress>
- <q>
- <script>
- <select>
- <source>
- <style>
- <table>
- <td>
- <th>
- <tr>
- <textarea>
- <title>
- <time>
- <track>
- <video>
HTML DOM Script defer Attribute
HTML DOM Script text Attribute
Script src Attribute
Example
Get the URL of an external script:
var x = document.getElementById("myScript").src
x outputs:
http://www.w3cschool.cc/jsref/demo_script_src.js
Definition and Usage
The src attribute sets or returns the value of the src attribute of a script.
The src attribute specifies the URL of an external script file.
If you want to run the same JavaScript on several pages in your site, you should create an external JavaScript file, instead of writing the same script over and over again. Save the script file with a .js extension, and refer to it using the src attribute in the <script> tag.
Note: The external script file cannot contain script tags.
Note: Reference the external script file correctly that you write into the script.
Browser Support
All major browsers support the src attribute.
Syntax
Return the src property:
scriptObject.src
Set the src property:
scriptObject.src=URL
Property Values
| Value | Description |
|---|---|
| URL | The URL of the external script file. Possible values:
|
Technical Details
| Return Value: | A String, representing the URL of the external script file. Returns the full URL, including the protocol (like http://). |
|---|
Related Articles
HTML Reference: HTML <script> src Attribute
YouTip