TextTrackList: length property - Web APIs | MDN

Value

A number indicating how many text tracks are included in the TextTrackList. Each track can be accessed by treating the TextTrackList as an array of objects of type TextTrack.

Examples

This snippet gets the number of text tracks in the first media element found in the DOM by querySelector().

js

const mediaElem = document.querySelector("video, audio");
let numTextTracks = 0;

if (mediaElem.textTracks) {
  numTextTracks = mediaElem.textTracks.length;
}

Note that this sample checks to be sure HTMLMediaElement.textTracks is defined, to avoid failing on browsers without support for TextTrack.

Specifications

Specification
HTML
# dom-texttracklist-length

Browser compatibility

Help improve MDN

Learn how to contribute

This page was last modified on by MDN contributors.