small 'else-like' function: "instead" or "others"
I posted a small function I wrote to the main jQuery English group.
Originally I called it "else" which works in Firefox, but as a
reserved word breaks Safari, so "instead," "others," or "otherswise"
would be a better term.
http://groups.google.com/group/jquery-en/browse_thread/thread/6be2a127822a108d/5b515a940aaeb33f#5b515a940aaeb33f
Essentially, it allows you to write else-like statements in your
chain, immediately end()ing a previous destructive operation and
filter()ing to everything else that had not been previously matched.
The function:
jQuery.fn.instead = function() {
return this.end().not(this);
};
So you can replace the duplicated selector in this:
$("div")
.filter(".content:has(h1)")
.fadeTo(1000, 1)
.end()
.not(".content:has(h1)")
.fadeTo(1000, .75);
With this:
$("div")
.filter(".content:has(h1)")
.fadeTo(1000, 1)
.instead()
.fadeTo(1000, .75);