TextTrackList: addtrack event

The addtrack event is fired when a track is added to a TextTrackList.

Bubbles No
Cancelable No
Interface TrackEvent
Event handler property onaddtrack

Examples

Using addEventListener():

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:

const mediaElement = document.querySelector('video, audio');

mediaElement.textTracks.onaddtrack = (event) => {
  console.log(`Text track: ${event.track.label} added`);
};

Specifications

Specification
HTML Standard (HTML)
# event-media-addtrack

Browser compatibility

BCD tables only load in the browser

See also