195 of 264 menu

contains method of the classList object

The contains method of the classList object checks for the presence of an element's CSS class.

Syntax

element.classList.contains(class);

Example

We check if an element has the class ggg:

<p id="elem" class="www ggg zzz"></p> let elem = document.querySelector('#elem'); let contains = elem.classList.contains('ggg'); console.log(contains);

The code execution result:

true

See also

enru