That's already in the core :)

$('#no-defs').toggle( !$('.def').length );

http://docs.jquery.com/Effects/toggle#switch

- ricardo

On Apr 16, 5: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();
> >           }

Reply via email to