Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the contains () method of jquery

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report