src code

instance method Element#descendantOf

Element#descendantOf(ancestor) → Boolean
  • ancestor (Element | String) – The element to check against (or its ID).

Checks if element is a descendant of ancestor.

Example

Assuming:

<div id="australopithecus">
  <div id="homo-erectus">
    <div id="homo-sapiens"></div>
  </div>
</div>

Then:

$('homo-sapiens').descendantOf('australopithecus');
// -> true
 $('homo-erectus').descendantOf('homo-sapiens');
// -> 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.