Jake Verbaten wrote:
> JCM wrote:
>> If you want perfomance:
>> $('#x').find('tr.zebra').removeClass('zebra');
> If you want real performance don't use jQuery (which is an order of
> magnitude slower on average)
>
> var nodes = document.getElementById("x").getElementsByClassName("zebra");
>
> for (var i = 0, len = nodes.length; i < len; i++) {
> var node = nodes[i];
> if (node.tagName !== "TR") continue;
> var temp = (" " + node.className + " ");
> temp.replace(" zebra ", "");
> node.className = temp.trim();
> }
However, the jQuery solution works for me in IE7 and IE8, which I have
to support. You solution doesn't, even when I polyfill `.trim()`,
because those browsers also don't support `.getElementsByClassName()`.
In my quick test [1], your solution performs better than jQuery in
Firefox (only by about half an order of magnitude, not a full order.)
They perform the same in Chrome 15 and Android. But without writing a
polyfill for gEBCN, I can't even test in older IEs.
And, as someone else has pointed out, this is not likely something
that will run in a tight loop. So does it really matter that it can
be run 100,000 times per second rather than a mere 30,000?
-- Scott
[1] http://jsperf.com/zebra-dom-vs-jquery
--
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]