jQuery: difference between filter and find -
this question has answer here:
- difference between find , filter 4 answers
what difference between filter , find function in jquery ?? filter function , find function same job in jquery according experience. can tell difference between them?
the find method, retrieves group of elements match given selector.
var items = $( "#group" ).find( "#.item" ); // finds items within group the filter method can reduce matched elements smaller collection selector.
var special_items = items.filter( ".special" ); // extract "special" items essentially, can both same job. simulate find function filter passing every element filter function. doesn't make sense might know when trying understand difference between them.
the following 2 commands yield same number of elements:
$( document ).find( "a" ).length $( "*" ).filter( "a" ).length with regard performance consideration ever can, limit number of elements need scanned.
Comments
Post a Comment