Home > Web Front-end > JS Tutorial > body text

Example of usage of find() method in jQuery_jquery

WBOY
Release: 2016-05-16 16:21:48
Original
1309 people have browsed it

The example in this article describes the usage of find() method in jQuery. Share it with everyone for your reference. The specific analysis is as follows:

This method gets the child elements of all elements in the matching element collection and deletes them by selector, jQuery object or element.
The find() method is a good way to get descendant elements of the matching element.

Note: children() only gets first-level child elements, while find() will find all child elements.

Grammar structure 1:

Copy code The code is as follows:
$(selector).find(expr)

Parameter list:

参数 描述
expr 字符串值,定义筛选表达式。

Example code:

Copy code The code is as follows:






children() function-Script Home






I am grandson p



I am my sonp



I am a brotherp




The above code can set the font color of all p elements under the father element to red.

Grammar structure 2:

Copy code The code is as follows:
$(selector).find(element)

Can find the specified element under the matching element.

Parameter list:

参数 描述
element 用于匹配元素的DOM对象或者jQuery对象。

예제 코드:

코드 복사 코드는 다음과 같습니다.






find() 함수-스크립트 홈