HTML DOMTokenList contains() Method

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");

Try It Yourself

Example 2

Add the "myStyle" class to the element:

const list = element.classList;
list.add("myStyle");

Try It Yourself

Example 3

Remove the "myStyle" class from the element:

const list = element.classList;
list.remove("myStyle");

Try It Yourself

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

length Property

item() Method

add() Method

remove() Method

replace() Method

toggle() Method

forEach() Method

keys() Method

values() Method

DOMTokenList Object