Thanks, Karl and Dave for your help on this.

I liked Dave's more compact code, this made me understand a little bit
more of how jQuery works, so I'm going with that for now.

Karl, I appreciate your reply as well, since speed might be a concern
in the near future. I'll keep that advice in mind along the way.

This thing is AMAZING!

Thanks again,
Marcelo Avim.

On Oct 10, 6:33 pm, Dave Methvin <[EMAIL PROTECTED]> wrote:
> > // save old active menu
> > var oldActive = $("#mainnav li.active");
>
> > // clear actives
> > $("#mainnav li.active").removeClass("active");
>
> > // activate current
> > $("#mainnav li a").filter(function() {
> >         return isCurrent(this, 'href');
>
> > }).parent().addClass("active");
>
> > // re-activate old one if nothing is active
> > if($("#mainnav li.active").length == 0) {
> >         oldActive.addClass("active");
>
> > }
>
> Maybe something like this (untested)?
>
> $("#mainnav li a")
>   .filter(function() { return isCurrent(this, 'href'); })
>   .parent()
>     .siblings(".active").removeClass("active").end()
>     .addClass("active")
>
> I think it handles the same two cases as the original code.
>
> 1) The filter returns a node matching href; we get the parent li and
> from there the current active sibling. Then we remove the active class
> from it and end() back to the li matching the href. That one gets the
> active class.
>
> 2) The filter matches no href; the matched node set in the jQuery
> object is empty and the rest of the chain is a no-op. Since nothing is
> changed, the original active node retains its class.

Reply via email to