This article mainly introduces the filtering operations in jquery. For more information, see.
1. Filter Filtering
Name |
Description |
Example |
Eq (index) |
Obtain the nth Element |
Obtain the Second Matching Element: $ ("P"). eq (1) |
Filter (expr) |
Filters out a set of elements that match the specified expression. |
Retain the elements with the select class: $ ("P"). filter (". selected ") |
Filter (fn) |
Filters out a set of elements that match the specified function return value. This function will calculate each object once (as in '$. each'). If the called function returns false, this element will be deleted, otherwise it will be retained. |
The reserved sub-element does not contain ol elements:
$ ("P"). filter (function (index ){ Return $ ("ol", this). size () = 0; }); |
Is (expr)
Note: This function returns a Boolean value instead of a jQuery package set. |
Use an expression to check the selected element set. If at least one element matches the given expression, true is returned. If no element matches, or the expression is invalid, 'false'. 'filter' is actually called internally. Therefore, the original rules of the filter () function are also applicable here. |
Returns true because the parent element of an input element is a form element: $ ("Input [type = 'checkbox']"). parent (). is ("form ") |
Map (callback) |
Convert a group of elements into other arrays (whether or not they are element arrays) You can use this function to create a list, whether it is a value, attribute, CSS style, or other special form. You can use '$. map ()' to easily create |
Create a list of values of each input element in form:
$ ("P"). append ($ ("input"). map (function (){ Return $ (this). val (); }). Get (). join (",")); |
Not (expr) |
Deletes an element that matches the specified expression. |
Delete an element with a select ID from element p: $ ("P"). not ($ ("# selected") [0]) |
Slice (start, end) |
Select a matched subset |
Select the first p element: $ ("P"). slice (0, 1 ); |