Favorites

DOM DOMTokenList.contains() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
DOMTokenList.contains()
DOM DOMTokenList MethodThis method is supported by all modern browsers.
Updated 28th November 2026

The contains() method of a DOMTokenList, usually element.classList.contains(), checks whether an element has a class.

Description

The contains() method returns whether the list includes the given token, for example whether an element has a class. element.matches('.name') does the same check using a selector.

The check is case-sensitive, so contains('Active') doesn't match a class named active. Passing a string with spaces won't find multiple classes; check each one separately, or use matches('.a.b') to require both.

Before changing state based on a class, checking contains() lets you decide what to do next, though toggle()'s return value already tells you the new state when you're switching a class anyway.

Syntax

tokenList.contains(token)

Parameters

  • tokenThe token (class name) to look for.

Return Value

true if the list contains the token, otherwise false.

Example

<ul><li class="item active">Home</li></ul>
const item = document.querySelector('li');
console.log(item.classList.contains('active'));
console.log(item.classList.contains('disabled'));

Browser Support

The following information will show you the current browser support for the DOMTokenList.contains() method. Hover over a browser icon to see the version that first introduced support for this method.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee