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