Categories

jQuery.contains()

Categories: Utilities

jQuery.contains( container, contained )Returns: Boolean

Description: Check to see if a DOM element is within another DOM element.

  • jQuery.contains( container, contained )

    version added: 1.0

    container   The DOM element that may contain the other element.

    contained   The DOM element that may be contained by the other element.

  • Check if an element is inside another. Text and comment nodes are not supported.

    Code:
    jQuery.contains(document.documentElement, document.body); // true
    jQuery.contains(document.body, document.documentElement); // false