4 ms·
Out of curiousity I tested that particular statement, and you're right. Compared to $('#foo').attr('bar', 'baz'); your code is 30 times faster in Chrome
by rorrr 16y ago
Out of curiousity I tested that particular statement, and you're right. Compared to
$('#foo').attr('bar', 'baz');
your code is
30 times faster in Chrome 9
81 times faster in Firefox 3.6
- tropin 16y agoCould you share your test code?
- ams6110 16y agoIn most cases, though, using jquery to do something like adding a class, or setting a value, is still plenty fast enough. We're talking about code that runs in the browser, where things move on human timescales. Don't optimize prematurely.
- bzbarsky 16y agoThe problems start when you add a class to 10,000 elements on the page. And yes, I've seen pages doing this with jquery where the jquery overhead was what made the difference between a 20ms operation (not user-perceptible) and a 1s operation (very much user-perceptible).
- mazuhl 16y ago47 times faster in Firefox 3.6.1 7 times faster in IE 8