jQuery.contains() method
Example
Check whether one element is contained within another:
$(function () {
function funcontain( html ){
document.body.innerHTML += "
" + html;
}
funcontain($.contains( document.documentElement, document.body )); // true
funcontain($.contains( document.body, document.documentElement )); // false
})
Try it »
Definition and Usage
The $.contains() method is used to determine whether a specified element contains another element, that is, whether another DOM element is a descendant of the specified DOM element.
Syntax
$
.contains( container, contained )
| Parameters | Description |
|---|---|
| container | Element type: The ancestor container element that may contain other elements. |
| contained | Element type: The descendant element that may be contained by other elements. |
jQuery Miscellaneous Methods