""> "" />
Easy Tutorial
❮ Misc Callbacks Event Data ❯

jQuery.contains() Method

jQuery Miscellaneous Methods

Example

Detect whether one element is contained within another element:

$(function () { 
    function funcontain( html ){
        document.body.innerHTML += "<br>" + html;
        }
    funcontain($.contains( document.documentElement, document.body )); // true
    funcontain($.contains( document.body, document.documentElement )); // false
})

Definition and Usage

The $.contains() method is used to determine whether a specified element contains another element. It checks if the other DOM element is a descendant of the specified DOM element.


Syntax

Parameter Description
container Element type The ancestor container element that may contain other elements.
contained Element type The descendant element that may be contained within other elements.

jQuery Miscellaneous Methods

❮ Misc Callbacks Event Data ❯