jQuery.contains()

Check to see if a DOM element is a descendant of another DOM element.

The $.contains() method returns true if the DOM element provided by the second argument is a descendant of the DOM element provided by the first argument, whether it is a direct child or nested more deeply. Otherwise, it returns false. Only element nodes are supported; if the second argument is a text or comment node, $.contains() will return false.

Note: The first argument must be a DOM element, not a jQuery object or plain JavaScript object.

version added: 1.4
container

The DOM element that may contain the other element.

contained

The DOM element that may be contained by (a descendant of) the other element.

Examples:

Check if an element is a descendant of another.

$.contains( document.documentElement, document.body ); // true
$.contains( document.body, document.documentElement ); // false
doc_jQuery
2016-03-27 13:48:30
Comments
Leave a Comment

Please login to continue.