{{APIRef("DOM")}}{{gecko_minversion_header("1.9.2")}}
The DOMTokenList
interface represents a set of space-separated tokens. Such a set is returned by {{domxref("Element.classList")}}, {{domxref("HTMLLinkElement.relList")}}, {{domxref("HTMLAnchorElement.relList")}} or {{domxref("HTMLAreaElement.relList")}}. It is indexed beginning with 0
as with JavaScript {{jsxref("Array")}} objects. DOMTokenList
is always case-sensitive.
Properties
This interface doesn't inherit any property.
- {{domxref("DOMTokenList.length")}} {{ReadOnlyInline}}
- Is an
integer
representing the number of objects stored in the object.
Methods
This interface doesn't inherit any method.
- {{domxref("DOMTokenList.item()")}}
- Returns an item in the list by its index (or undefined if the number is greater than or equal to the length of the list, prior to {{gecko("7.0")}} returned null)
- {{domxref("DOMTokenList.contains()")}}
- Returns
true
if the underlying string contains token, otherwisefalse
- {{domxref("DOMTokenList.add()")}}
- Adds token to the underlying string
- {{domxref("DOMTokenList.remove()")}}
- Removes token from the underlying string
- {{domxref("DOMTokenList.replace()")}}
- Replaces an existing token with a new token.
- {{domxref("DOMTokenList.supports()")}}
- Returns
true
if a given token is in the associated attribute's supported tokens. - {{domxref("DOMTokenList.toggle()")}}
- Removes token from string and returns false. If token doesn't exist it's added and the function returns true
Specifications
Specification | Status | Comment |
---|---|---|
{{SpecName("DOM WHATWG", "#interface-domtokenlist", "DOMTokenList")}} | {{Spec2("DOM WHATWG")}} | Initial definition |
Browser compatibility
{{CompatibilityTable}}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|
Basic support | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | 10 | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
Feature | Android | Android Webview | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile | Chrome for Android |
---|---|---|---|---|---|---|---|
Basic support | {{CompatUnknown}} | {{CompatVersionUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatVersionUnknown}} |
See Also
- {{domxref("DOMSettableTokenList")}} (object that extends DOMTokenList with settable .value property)