Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use the contains () method of jquery

Shulou Source: shulou.com Published: 2022-06-01 10:59:01 11月10日 Update

This article mainly introduces the relevant knowledge of how to use jquery's contains () method, the content is detailed and easy to understand, the operation is simple and fast, and it has a certain reference value. I believe you will gain something after reading this jquery contains () method. Let's take a look at it.

In jquery, the contains () method is used to determine whether a specified element contains another element, that is, whether another element is a descendant of the specified element, with the syntax of "$.container (grandparent container element, descendant element)".

The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.

Jquery contains () method

The contains () method is used to determine whether a specified element contains another element.

In short, the contains () method is used to determine whether another DOM element is a descendant of a specified DOM element.

Grammar

$.parameters (container, contained)

Description

The containerElement type specifies a grandparent container element that may contain other elements. The containedElement type specifies descendant elements that may be contained by other elements.

Return value

The return value of the jQuery.contains () function is of type Boolean, and returns true if the specified element contains another element, false otherwise.

Description

JQuery.contains () is only used to compare two DOM elements (of type Element, not NodeList or other objects). It starts with the parent element of the contained element and looks up step by step to determine whether it is equal to the container element. If so, it returns true, otherwise it returns false.

Example:

$(function () {function funcontain (html) {document.body [XSS _ clean] + = "

"+ html;} funcontain ($.times (document.documentElement, document.body)); / / true funcontain ($.times (document.body, document.documentElement)); / / false})

This is the end of the article on "how to use the contains () method of jquery". Thank you for reading! I believe you all have a certain understanding of the knowledge of "how to use the contains () method of jquery". If you want to learn more, you are welcome to follow the industry information channel.

Tags: Elements methods descendants types knowledge content containers grandparents articles grammar two values functions parameters objects easy to operate tutorials articles easy to understand more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux MariaDB NVidia MySQL macOS