jQuery: use filter(), but work with both results
- by Tomalak
In jQuery, filter() reduces your result to those elements that fulfill a certain condition.
This splits the list in two parts. Working with the "good half" of the elements is easy:
$("some selector").filter(function() {
// determine result...
return result;
}).each( /* do something */ );
But how can I work with the "other half" of my elements, too - but without doing the equivalent of this:
$("some selector").filter(function() {
// determine result...
return !result;
}).each( /* do something */ );
Basically, I'd like to feed two separate /* do something */ parts to a single filter. One for those that match, and one for the others - without having to select and filter twice.