An id on a <source> tag assigns an identifier to the source.
The identifier must be unique across the page.
An id attribute on a <source> tag.
<audio controls>
<source id="epic-music" src="/media/epic.mp3" type="audio/mpeg">
</audio>
The id attribute assigns an identifier to the <source> element.
The id allows JavaScript to easily access the <source> element.
It is also used to point to a specific id selector in a style sheet.
Tip: id is a global attribute that can be applied to any HTML element.
<source id="identifier" />
Value | Description |
---|---|
identifier | A unique alphanumeric string. The id value must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens (-), underscores (_), colons (:), and periods (.). |
A <source> tag with a unique id.
Clicking the button displays the src attribute value of the element.
<audio controls>
<source id="mysource" src="/media/epic.mp3" type="audio/mpeg">
</audio>
<br /><br />
<button onclick="show();">Show source src</button>
<script>
let show = () => {
let element = document.getElementById("mysource");
alert("Src = " + element.src);
}
</script>
The id attribute assigns a unique identifier for the <source>.
Clicking the button calls JavaScript which locates the <source> using the id.
Finally, the src value of the <source> is displayed in an alert box.
Here is when id support started for each browser:
Chrome
|
4.0 | Jan 2010 |
Firefox
|
3.5 | Jun 2009 |
IE/Edge
|
9.0 | Mar 2011 |
Opera
|
10.5 | Mar 2010 |
Safari
|
4.0 | Jun 2009 |
Back to <source>