TextTrackList.length

The read-only TextTrackList property length returns the number of entries in the TextTrackList, each of which is a TextTrack representing one track in the media element.

A value of 0 indicates that there are no text tracks in the media.

Syntax

var trackCount = TextTrackList.length;

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.

Example

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

var mediaElem = document.querySelector("video, audio");
var 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

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
length
44
12
31
10
31
6
44
44
31
32
7
4.0

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