Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

jQuery.contains() method

jQuery.contains() method

jQuery Miscellaneous MethodsjQuery Miscellaneous Methods

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 MethodsjQuery Miscellaneous Methods