DOM DOMTokenList.add() Method
The add() method of a DOMTokenList, usually element.classList.add(), adds one or more classes. Classes already present are ignored.
Description
The add() method adds the given tokens to the list, most commonly adding CSS classes with element.classList.add(). Tokens that are already present aren't duplicated. Tokens can't contain spaces; pass several arguments to add several classes.
Because add() ignores classes that are already present, there's no need to check first with contains(). If the element had no class attribute before, one is created.
Adding a class and letting CSS do the styling keeps presentation in your style sheets, and makes it easy to combine with transitions: adding a class such as is-open can trigger a CSS transition defined on that class.
Syntax
tokenList.add(token1, token2, ...)Parameters
- token1, token2, ...One or more tokens (class names) to add.
Return Value
None (undefined).
Example
Browser Support
The following information will show you the current browser support for the DOMTokenList.add() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





