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
$.fn.if = function(cond, ontrue, onfalse) {
this.each(function() {
if (cond.apply(this)) ontrue.apply(this);
else onfalse.apply(this);
});
};
$('some selector').if(function() {
// determine result
}, function() {
// do something
}, function() {
// do something else
});
I'm not sure it is much more readable than putting an if inside an each manually, though.