I just had some Doubt , the performance is great

On Jan 31, 11:54 am, Karl Swedberg <k...@englishrules.com> wrote:
> Hi Pedram,
>
> I agree with Nic. Especially if you're only dealing with 4 elements,  
> binding directly on them seems like the most sensible solution.
>
> Are you noticing performance problems? You shouldn't be seeing any,  
> with scripts this basic. In any case, there are a couple selector  
> optimizations you could implement, if necessary. Something like this:
>
> var $navBarLinks = $('#your-nav-bar-id a');
>
> $navBarLinks.click(function() {
>    $navBarLinks.removeClass('active');
>    $(this).addClass('active');
>
> });
>
> --Karl
>
> ____________
> Karl Swedbergwww.englishrules.comwww.learningjquery.com
>
> On Jan 31, 2009, at 2:36 PM, Pedram wrote:
>
>
>
> > I'm looking to improve the performance ,  which of these 2 codes has
> > the best performance.
>
> > On Jan 30, 1:04 am, Nic Luciano <adaptive...@gmail.com> wrote:
> >> What exactly are you trying to do, what is the issue? Maybe just  
> >> preference
> >> here (and I'm also just guessing what you're asking) but I don't  
> >> see a
> >> reason not to put the events on the elements themselves
>
> >> $("ul li a").click(function() {
> >>         $
> >> (this).parent().parent().find(".active").removeClass("active");
> >>         $(this).addClass("active");
> >>     });
>
> >> On Fri, Jan 30, 2009 at 3:07 AM, Pedram <pedram...@gmail.com> wrote:
>
> >>> Dear Karl ,
> >>> I know You are Expert in these Issues do you have any idea for me
> >>> Thanks
>
> >>> On Jan 29, 5:44 pm, Pedram <pedram...@gmail.com> wrote:
> >>>> Hi Folks ,
> >>>>   I have some links in my Navigation bar such as below , I Used  
> >>>> FIND
> >>>> in my code , does anyone has any better solution for me ,
> >>>>   I also used Event Delegation in the system .
>
> >>>> <ul>
> >>>>   <li><a href="#" class="active>a</a></li>
> >>>>   <li><a href="#">b</a></li>
> >>>>   <li><a href="#">c</a></li>
> >>>>   <li><a href="#">d</a></li>
> >>>> </ul>
>
> >>>>   $("ul").bind("click",function(e){
> >>>>       var clicked=$(e.target);
> >>>>       $(this).find("a.active").removeClass("active");
> >>>>       clicked.addClass("active");
> >>>>   });

Reply via email to