>>$allRows.find ('.shown').addClass("up");

should be replaced with

>>$allRows.filter('.shown').addClass("up");

find goes through all the descendants whereas filter goes through the
selected collection. Give it a try.

On Apr 20, 4:25 am, Brams <ibrahim.ba...@gmail.com> wrote:
> Hello,
>
> I've been reading up a lot on enhancing JavaScript code as well as
> utilizing JQuery in a proper manner. I tried to implement some of the
> techniques that I saw in order to see what performance gain i would
> get. I tried something out and i was sure that the change would
> enhance performance but it didn't. I just want to know if there's
> something that I'm missing:
>
> My Code before (The code below took around 90 ms to execute):
> ------------------------
>
> $("tr [name^='rowBatch'].shown").addClass("up");
> $("tr
> [name^='rowBatch']").not(':first').not(".shown").removeClass("notshown");
>
> My Code after (The code below took around 350 ms to execute)
> ---------------------
>
> var $allRows = $("tr [name^='rowBatch']");
> $allRows.find ('.shown').addClass("up");
> $allRows.not(':first').not(".shown").removeClass("notshown");
>
> What I don't understand is the increase in execution time! by caching
> into a local variable, I'm now traversing the DOM only once instead of
> twice. Is the 'find' or 'not' methods slowing things down? In your
> opinion, how can the code above be optimized.
>
> Thanks a lot!

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/jsmentors@jsmentors.com/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/jsmentors@googlegroups.com/

To unsubscribe from this group, send email to
jsmentors+unsubscr...@googlegroups.com

Reply via email to