HTML DOMTokenList contains() Method
- Previous Page add()
- Next Page entries()
- Go to Parent Page HTML DOMTokenList
Definition and Usage
If the DOMTokenList contains a class, the contains() method returns true; otherwise, it returns false.
Example
Example 1
Does the element have the "myStyle" class marker?
let x = element.classList.contains("myStyle");
Example 2
Add the "myStyle" class to the element:
const list = element.classList; list.add("myStyle");
Example 3
Remove the "myStyle" class from the element:
const list = element.classList; list.remove("myStyle");
Syntax
domtokenlist.contains(token)
Parameter
Parameter | Description |
---|---|
token | Required. The token to check. |
Return Value
Type | Description |
---|---|
Boolean Value | If the list contains a class, it returns true; otherwise, it returns false. |
Browser Support
All browsers support domtokenlist.contains():
Chrome | IE | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
Chrome | IE | Edge | Firefox | Safari | Opera |
Support | 10-11 | Support | Support | Support | Support |
Related Pages
- Previous Page add()
- Next Page entries()
- Go to Parent Page HTML DOMTokenList