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
The method recommended by Kobi in plugin form:
$.fn.invert = function() {
return this.end().not(this);
};
$('.foo').filter(':visible').hide().invert().show();
Note that invert() will not add a new element to the jQuery stack but replace the last one:
$('.foo').filter(':visible').invert().end(); // this will yield $('.foo'), not $('.foo:visible')
Edit: changed prevObject to end() at Tomalak's suggestion.