DOM DOMTokenList Interface
A DOMTokenList is a set of space-separated tokens, most often an element's classList, with methods to add, remove, toggle and check them.
Description
The DOMTokenList interface represents a set of space-separated tokens, such as the class names returned by element.classList, or the values of rel on links and sandbox on iframes. It's live, and changes are written back to the attribute.
Its methods are add(), remove(), toggle(), contains(), replace(), item() and supports(), and it has length, value and forEach().
The supports() method is only meaningful for attributes with a fixed set of allowed values, such as rel on links, where it tells you whether the browser understands a value like 'preload'. Tokens can't contain white space; passing a string with a space to add() or toggle() throws an InvalidCharacterError.
Methods
| Name | Description |
|---|---|
DOMTokenList.add() | The add() method of a DOMTokenList, usually element.classList.add(), adds one or more classes. |
DOMTokenList.contains() | The contains() method of a DOMTokenList, usually element.classList.contains(), checks whether an element has a class. |
DOMTokenList.remove() | The remove() method of a DOMTokenList, usually element.classList.remove(), removes one or more classes. |
DOMTokenList.toggle() | The toggle() method of a DOMTokenList, usually element.classList.toggle(), adds a class if it's missing and removes it if it's present. |
Example
Browser Support
The following information will show you the current browser support for the DOMTokenList interface. Hover over a browser icon to see the version that first introduced support for this interface.
Desktop





Tablets & Mobile





