TextTrackList: addtrack event
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The addtrack
event is fired when a track is added to a TextTrackList
.
Syntax
Use the event name in methods like addEventListener()
, or set an event handler property.
js
addEventListener("addtrack", (event) => {});
onaddtrack = (event) => {};
Event type
A TrackEvent
. Inherits from Event
.
Event properties
Examples
Using addEventListener()
:
js
const mediaElement = document.querySelector("video, audio");
mediaElement.textTracks.addEventListener("addtrack", (event) => {
console.log(`Text track: ${event.track.label} added`);
});
Using the onaddtrack
event handler property:
js
const mediaElement = document.querySelector("video, audio");
mediaElement.textTracks.onaddtrack = (event) => {
console.log(`Text track: ${event.track.label} added`);
};
Specifications
Specification |
---|
HTML Standard # event-media-addtrack |
HTML Standard # handler-tracklist-onaddtrack |
Browser compatibility
BCD tables only load in the browser
See also
- Related events:
removetrack
,change
- This event on
VideoTrackList
targets:addtrack
- This event on
AudioTrackList
targets:addtrack
- This event on
MediaStream
targets:addtrack
- Media Capture and Streams API
- WebRTC