W3cubDocs

/Web APIs

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.

js

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():

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

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
addtrack_event 23 12 31 11 ≤12.1 6 4.4 25 31 ≤12.1 7 1.5

See also

© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/TextTrackList/addtrack_event