src property (script)
Sets or retrieves the location of a file containing scripting code.
Syntax:
You can find the related objects in the Supported by objects section below.
This property is read/write.
HTML page for this property: src |
Possible values:
String that sets or retrieves the URL of the script file. It can be an absolute or relative path as well. Relative paths are relative to the base URL. The base URL is the location of the current document, but it can be overridden by the base tag.
Default: this property has no default value.
Example HTML code 1:
This example illustrates the use of the src attribute:
|
|||||
<head> <script type="text/javascript" src="javascript.js"></script> </head> <body> <button onclick="HelloWorld ();">Call HelloWorld function</button> </body> |
|||||
|
|||||
Did you find this example helpful?
|
Example HTML code 2:
This example illustrates the use of the src property:
|
|||||
<head> <script type="text/javascript" id="baseJS" src="javascript.js"></script> <script type="text/javascript"> function GetSrc () { var script = document.getElementById ("baseJS"); alert (script.src); } </script> </head> <body> <button onclick="GetSrc ();">Get script location!</button> <button onclick="HelloWorld ();">Call HelloWorld function</button> </body> |
|||||
|
|||||
Did you find this example helpful?
|
Supported by objects:
HTML elements:
Related pages:
External links:
User Contributed Comments