An id on a <track> tag assigns an identifier to the text track.
The identifier must be unique across the page.
An id attribute on a <track> element.
<video controls="controls" width="320" height="176">
<source src="/media/godfather.mp4" type="video/mp4" />
<source src="/media/godfather.ogg" type="video/ogg" />
<track id="godfather-track" src="/media/godfather.srt" kind="subtitles" srclang="es" label="Spanish" />
</video>
The id attribute assigns an identifier to the <track> element.
The id allows JavaScript to easily access the <track> 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.
<track 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 <track> tag with a unique id attribute.
Clicking the button displays the src value on the track element.
<video width="320" height="240" controls>
<source src="/media/movie.mp4" type="video/mp4">
<source src="/media/movie.ogg" type="video/ogg">
<track id="mytrack" src="/media/movie.srt" kind="subtitles" srclang="es" label="Spanish" />
</video>
<br /><br />
<button onclick="show();">Show track src</button>
<script>
let show = () => {
let element = document.getElementById("mytrack");
alert("Src = " + element.src);
}
</script>
The id attribute assigns a unique identifier for the <track>.
Clicking the button calls JavaScript which locates the <track> using the id.
Finally, the src value of the track is displayed in an alert box.
Here is when id support started for each browser:
Chrome
|
18.0 | Mar 2012 |
Firefox
|
31.0 | Jul 2014 |
IE/Edge
|
10.0 | Sep 2012 |
Opera
|
15.0 | Jul 2015 |
Safari
|
6.0 | Jul 2012 |
Back to <track>