Hi.
According to QUnit it makes no difference which approach you choose. But
caching the elements, like:
var $elem = $('#x tr.zebra');
…or …
var $elem = $('#x').find('tr.zebra');
… improves the speed by a few millseconds. According to a QUnit-test with a
table that contains 36 tr-elements, where 18 of them have the class "zebra".
I hope this helps a bit.
Regards
Emanuel
Am Donnerstag, 5. Januar 2012 um 15:46 schrieb Andraž Kos:
> Hello,
>
> I would like your opinion on which one is better practice (example in jQuery
> code) for fast executing code:
>
>
> $('#x tr.zebra').removeClass('zebra');
>
> vs
>
> $('#x tr').removeClass('zebra');
>
>
> First one will select only targeted items, then run the remove function only
> where needed.
> Second one will select all possible targets without taking time to filter
> them, then run the code on each one.
>
> Which one would you use more often and reasons why?
>
>
> Take care
> Andraž
>
> --
> 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]
> (mailto:[email protected])
--
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]