This article mainly introduces information about node operation methods such as each (), find (), and filter () in jQuery. It is very helpful and has reference value. If you need it, refer to section 1. each (callback)
Official explanation:
Returned value: jQuery
Overview
Execute a function using each matching element as the context.
This means that each time the passed function is executed, the this keyword in the function points to a different DOM element (each time it is a different matching element ). In addition, each time a function is executed, a numeric value indicating the position of the element used as the execution environment in the matched element set is passed to the function as the parameter (an integer starting from scratch ). If 'false' is returned, the loop is stopped (just like using 'Break' in a normal loop '). Return 'true' to jump to the next loop (just like using 'contine' in a normal loop ').
Parameters
Callback
The function to be executed for each Matching Element
Example
Description:
Iterate two images and set their src attributes. Note: this indicates a DOM object instead of a jQuery object.
HTML code:
JQuery code:
$("img").each(function(i){this.src = "test" + i + ".jpg";});
Result:
[ , ]
2. find (expr | obj | ele)
Official explanation:
Returned value: jQuery
Overview
Searches for all elements that match the specified expression. This function is a good way to find the child element of the element being processed.
All searches rely on jQuery expressions. This expression can be written using the selector syntax of the CSS1-3.
Parameters
Expr String
Expression used for searching
JQuery object
A jQuery object used to match Elements
Element DOMElement
A dom Element
Example
Description:
Search for the following span element from all paragraphs. Same as $ ("p span.
HTML code:
Hello, how are you?
JQuery code:
$("p").find("span")
Result:
[Hello]
3. filter (expr | obj | ele | fn)
Official explanation:
Overview
Filters out a set of elements that match the specified expression.
This method is used to narrow the matching range. Multiple Expressions separated by commas
Parameters
Expr String
String value, which contains the selector expression used to match the current element set.
JQuery 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 set of test elements. It accepts an index parameter, which is the index of the element in the jQuery set. In a function, this indicates the current DOM element.
Example
Description of the selector parameter:
Retain elements with select classes
HTML code:
Hello
Hello Again
And Again
JQuery code:
$("p").filter(".selected")
Result:
[
And Again
]
The above section describes the detailed (recommended) knowledge of node operation methods such as each (), find (), and filter () in jQuery, which I hope to help you, if you have any questions, please leave a message and the editor will reply to you in time. I would like to thank you for your support for PHP chinnet!
For more information about node operation methods such as each (), find (), and filter () in jQuery (recommended), please follow the PHP Chinese network!