1. Filtering
|
Description | Example | ||||||||||||||||||||||||
eq( index ) | Get the Nth element | Get the second matched element: $("p").eq(1) |
||||||||||||||||||||||||
filter( expr ) | Filter out the set of elements matching the specified expression. | Retain elements with select class: $("p").filter(".selected") |
||||||||||||||||||||||||
filter( fn ) | Filter out the set of elements that match the return value of the specified function This function will internally calculate each object once (just like '$.each'). If the called function returns false, the element is deleted, otherwise it is retained. | Retain elements that do not contain ol among the child elements: $("div").filter(function(index) { return $("ol", this).size() == 0; }); | ||||||||||||||||||||||||
is( expr) Note: This function returns not a jQuery wrapper set but a Boolean value |
Use an expression to check the currently selected set of elements, and return true if at least one element matches the given expression. If no elements match, or the expression is invalid, 'false' is returned. 'filter' actually calls this function internally, so the original rules of the filter() function also apply here. | Since the parent element of the input element is a form element, true is returned: $("input[type='checkbox']").parent().is("form" ) |
||||||||||||||||||||||||
map( callback ) | Convert a set of elements into other arrays (whether it is an array of elements or not) You can use this function to create a list, whether it is a value, attribute, CSS style, or other special form. This can be easily established using '$.map()' | Create a list of the values of each input element in the form: $("p").append( $("input").map(function(){ return $(this).val(); }).get().join( ", ") ); |
||||||||||||||||||||||||
not( expr ) | Delete elements matching the specified expression | Remove the element with the ID of select from the p element: $("p").not( $("#selected")[0] ) |
||||||||||||||||||||||||
slice( start, end ) | Select a matching subset | Select the first p element: $("p").slice(0, 1); |