Home >Web Front-end >JS Tutorial >Detailed explanation of usage examples of find() and filter() operations in jQuery

Detailed explanation of usage examples of find() and filter() operations in jQuery

伊谢尔伦
伊谢尔伦Original
2017-07-19 14:10:062631browse

find(expr|obj|ele)

Official explanation:

Return value: jQuery

Overview

Search for all elements that match the specified expression. This function is a great way to find out the descendant elements of the element being processed.

All searches rely on jQuery expressions. This expression can be written using CSS1-3 selector syntax.

Parameters

expr String
Expression used to find
jQuery object object
One used to match elements jQuery object
element DOMElement
A DOM element

Example

##Description:

Start from all paragraphs and search further for span elements below. Same as $("p span").


HTML code:

<p><span>Hello</span>, how are you?</p>

jQuery code:



$("p").find("span")

Result:


[ 45a2772a6b6107b401db3c9b82c049c2Hello54bdf357c58b8a65c66d7c19c8e4d114 ]


#filter(expr|obj|ele|fn)
Official explanation:


Overview

Filter out the set of elements that match the specified expression.


This method is used to narrow the matching scope. Separate multiple expressions with commas


Parameters


expr String

String value containing selectors for matching the current set of elements expression.

jQuery object object
Existing jQuery object to match the current element.
element Expression
A DOM element used to match elements.
function(index) Function
A function is used as a collection of test elements. It accepts a parameter index, which is the index of the element in the jQuery collection. In functions, this refers to the current DOM element.


Example


Parameter selector description:


Retain with select class Element


HTML code:


<p>Hello</p><p>Hello Again</p><p class="selected">And Again</p>

jQuery code:


$("p").filter(".selected")

Result:


[ 27ec8ff0d0eb2aeaabbd785252528076And Again94b3e26ee717c64999d7867364b1b4a3 ]

The above is the detailed content of Detailed explanation of usage examples of find() and filter() operations in jQuery. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn