TextTrackList: addtrack event

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.

addEventListener('addtrack', (event) => { })

onaddtrack = (event) => { }

Event type

Event properties

In addition to the properties listed below, properties from the parent interface, Event, are available.

track Read only

The TextTrack object to which the event refers.

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
# event-media-addtrack
HTML Standard
# handler-tracklist-onaddtrack

Browser compatibility

BCD tables only load in the browser

See also