I'd be careful with code like that. It is terse, and very elegant, but not
all that readable from a "coding for the next guy" mentality.
 

  _____  

From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] On
Behalf Of Joseph Le Brech
Sent: Thursday, April 16, 2009 4:12 PM
To: jquery-en@googlegroups.com
Subject: [jQuery] Re: Shorten the JQuery code


I'm impressed by the [] brackets, does that eval() the 'hide' and 'show'
strings?

> Date: Thu, 16 Apr 2009 14:08:09 -0700
> Subject: [jQuery] Re: Shorten the JQuery code
> From: michaell...@gmail.com
> To: jquery-en@googlegroups.com
> 
> 
> $('#no-defs')[$('.def').length==0?'show':'hide']();
> 
> On Apr 16, 1:54 pm, MorningZ <morni...@gmail.com> wrote:
> > There isn't much you can do with that since you can't conditionally
> > code in ".show" or ".hide" unless you made a plugin to pass in a true/
> > false parameter and decide in the plugin, for instance
> >
> > $("#no_defs").conditionalShow($('.def').length == 0);
> >
> > On Apr 16, 4:27 pm, Dragon-Fly999 <dragon-fly...@hotmail.com> wrote:
> >
> > > Could someone tell me how to shorten the following code? Thanks.
> >
> > >           if ($('.def').length == 0) {
> > >             $('#no-defs').show();
> > >           }
> > >           else {
> > >             $('#no-defs').hide();
> > >           }


  _____  

Surfing the web just got more rewarding. Download the New Internet Explorer
8 <http://extras.uk.msn.com/internet-explorer-8/?ocid=T010MSN07A0716U>  

Reply via email to