Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Message from discussion small and maybe useful "else" extension
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
oliver  
View profile  
 More options Aug 8 2008, 9:36 pm
From: oliver <oliverlan...@gmail.com>
Date: Fri, 8 Aug 2008 18:36:03 -0700 (PDT)
Local: Fri, Aug 8 2008 9:36 pm
Subject: small and maybe useful "else" extension
I sometimes have the need to select a group of elements, perform one
action on one or more, and a different action on the rest of them, for
example:

$("div")
    .eq(1)
        .fadeTo(1000, 1)
    .end()
    .not(":eq(1)")
        .fadeTo(1000, 0);

This is a trivial example, but sometimes the "eq(1)" is a more
complicated selector which needs to be entered into both a filter()
and a not() operation.

As a shorthand, I wrote a small extension:
jQuery.fn.else = function() {
        return this.end().not(this);

};

$("div")
    .eq(1)
        .fadeTo(1000, 1)
    .else()
        .fadeTo(1000, 0);

(I realize else is a reserved word: it works in Firefox, but you could
also use "others" if you want to avoid the potential conflict.)

oliver


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google