matches method
The matches
method allows you
to check if an element matches the
specified CSS selector.
Syntax
element.matches('selector');
Example
We check if our element is
the paragraph with the class
www
:
<p id="elem" class="www"></p>
let elem = document.querySelector('#elem');
console.log(elem.matches('p.www'));
The code execution result:
true