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 »
The contains()
method returns true
if a DOMTokenList contains a class, otherwise false
.
domtokenlist.contains(token)
Parameter | Description |
token | Required. The token to check for. |
Type | Description |
Boolean | true if the list contains a class, otherwise false . |
domtokenlist.contains()
is supported in all browsers:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | 10-11 | Yes | Yes | Yes | Yes |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!