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/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to