This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

length

Summary

Returns the number of tokens in a DOMTokenList.

Property of dom/DOMTokenListdom/DOMTokenList

Syntax

Note: This property is read-only.

var result = element.length;

Return Value

Returns an object of type NumberNumber

Examples

//returns the number of classes in an element's classList (a DOMTokenList)
function elNumClasses(elid) {
  var classes = document.getElementById(elid).classList;
  return classes.length;
}

Related specifications

W3C DOM4
Candidate Recommendation