DOMTokenList: length property
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The read-onlylength property of theDOMTokenList interface is aninteger representing the numberof objects stored in the object.
In this article
Value
A positive integer, or0 if the list is empty.
Examples
In the following example we retrieve the list of classes set on a<span> element as aDOMTokenList usingElement.classList, then write the length of the list to the<span>'sNode.textContent.
First, the HTML:
html
<span></span>Now the #"span");const classes = span.classList;const length = classes.length;span.textContent = `classList length = ${length}`;
The output looks like this:
Specifications
| Specification |
|---|
| DOM> # ref-for-dom-domtokenlist-length①> |