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 [[../../../../Glossary/DOM|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
| Specification | Status | Comment |
|---|---|---|
| HTML Living StandardThe definition of 'TextTrackList: length' in that specification. | Living Standard |
Browser compatibility
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
length
|
Chrome
Full support 44 |
Edge
Full support ≤18 |
Firefox
Full support Yes |
IE
? |
Opera
Full support 31 |
Safari
Full support 10 |
WebView Android
Full support 44 |
Chrome Android
Full support 44 |
Firefox Android
? |
Opera Android
Full support 32 |
Safari iOS
? |
Samsung Internet Android
Full support 4.0 |
Legend
- Full support
- Full support
- Compatibility unknown
- Compatibility unknown
TextTrackList.length by Mozilla Contributors is licensed under CC-BY-SA 2.5.