src code

class method Element.match

Element.match(element, selector) → boolean
  • selector (String) – A CSS selector.

Checks if element matches the given CSS selector.

Examples
<ul id="fruits">
  <li id="apples">
    <ul>
      <li id="golden-delicious">Golden Delicious</li>
      <li id="mutsu" class="yummy">Mutsu</li>
      <li id="mcintosh" class="yummy">McIntosh</li>
      <li id="ida-red">Ida Red</li>
    </ul>
  </li>
</ul>

Then:

$('fruits').match('ul');
// -> true
 $('mcintosh').match('li#mcintosh.yummy');
// -> true
 $('fruits').match('p');
// -> false

This method can be called either as an instance method or as a generic method. If calling as a generic, pass the instance in as the first argument.