contains method of the classList object

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

Syntax

javascriptelement.classList.contains(class);

Example

We check if an element has the class ggg:

html<p id="elem" class="www ggg zzz"></p>
javascriptlet elem = document.querySelector('#elem');

let contains = elem.classList.contains('ggg');
console.log(contains);

The code execution result:

javascripttrue

See also