Source srcAttribute
Example
Return the URL of the media file:
var x = document.getElementById("mySource").src;
xThe output result is:
https://www.example.com/try/demo_source/horse.mp3
Try it yourself »
Definition and Usage
The src attribute sets or returns the value of the src attribute in the <source> element.
The src attribute specifies the URL of the media file to be played.
Note:The <source> element is new in HTML5.
Note:Internet Explorer 8 and earlier versions only return the file name (e.g., horse.mp3) rather than the URL (e.g., http://www.w3cschool.cc/jsref/horse.mp3).
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the src attribute.
Syntax
Return the src attribute:
sourceObject.src
Set the src attribute:
sourceObject.src=URL
Attribute Values
| Value | Description |
|---|---|
| URL | Specifies the URL of the media file. Possible values:
|
Technical Details
| Return value: | A string representing the URL of the media file. Returns the full URL, including the protocol (e.g., http://). |
|---|
Related Articles
HTML Reference Manual:HTML <source> src Attribute
Other Extensions
Source Object