HTML DOMTokenList contains()
❮ The DOMTokenList ObjectExamples
Does an an element has a "myStyle" class token?
let x = element.classList.contains("myStyle");
Try it Yourself »
Add a "myStyle" class to an element:
const list = element.classList;
list.add("myStyle");
Try it Yourself »
Remove the "myStyle" class from an element:
const list = element.classList;
list.remove("myStyle");
Try it Yourself »
Definition and Usage
The contains()
method returns true
if a
DOMTokenList contains a class, otherwise false
.
See Also:
Syntax
domtokenlist.contains(token)
Parameters
Parameter | Description |
token | Required. The token to check for. |
Return Value
Type | Description |
Boolean | true if the list contains a class, otherwise false . |
Browser Support
domtokenlist.contains()
is supported in all browsers:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | 10-11 | Yes | Yes | Yes | Yes |
❮ The DOMTokenList Object