3 ms·
Vanilla JS is more efficient than jQuery a lot of the time - for example, consider the $(...) api - this has to do string parsing before it makes its selector c
by Bahamut 12y ago
Vanilla JS is more efficient than jQuery a lot of the time - for example, consider the $(...) api - this has to do string parsing before it makes its selector call, which by its very nature take away computing power.
These days it is negligible though. The argument for using jQuery for DOM manipulation is oftentimes just one of readability.
- tonyonodi 12y agoIIRC jQuery started out using string parsing to achieve this but its widespread use prompted browser vendors to add the document.querySelector and document.querySelectorAll methods to their browsers. Probably in older browsers it still uses the old method but for modern browsers it just passes [selctor] in $("[selector]") through document.querySelectorAll; no string parsing necessary.
- enraged_camel 12y agoI think by "efficiency" the author meant developer efficiency, as in writing more code in less time. I may be wrong though. You're definitely right that vanilla JS is often times more efficient than jQuery.
- pkorzeniewski 12y agoIn 99% cases the performance difference doesn't matter - users won't notice that a jQuery method runs 5ms slower than it would run in vanilla JS, but they will notice if the script doesn't work at all, because your vanilla JS code fails on older browsers.
- Bahamut 12y agoI agree for the most part - I'm just making a theoretical distinction.