Is document.querySelector older than jQuery? I read than jQuery is using another way to cross through the DOM and that should be faster? (I made few online tests to run in my browser and jQuery was always slower) Is querySelector became updated and then faster?
Asked
Active
Viewed 85 times
0
-
*"I read that XYZ..."* always include the source of claims like this. – Tomalak Jul 16 '20 at 09:56
-
1https://caniuse.com/#feat=queryselector - jquery was around *long* before IE9. Later versions of jquery use native methods where available, so they'll be a tiny overhead for using jquery but otherwise the same. – freedomn-m Jul 16 '20 at 10:39
-
1*"Is `querySelector` older than jQuery?"* - No. `querySelector` is a browser feature that became widely implemented many years after jQuery was born. *"Is it faster?"* No, jQuery's [selection engine "Sizzle"](https://github.com/jquery/sizzle) is implemented in JavaScript and cannot compete with a native implementation. But Javascript is plenty fast and unless you have actually measured and found out that CSS selection, of all things, is the bottleneck of your application, I would not worry about it. There are a million other things things that can be slow. – Tomalak Jul 16 '20 at 10:42
-
1The main reason to use jQuery remains the same: It's a stable, cross-browser platform mitigates differences in browser capabilites, or even bugs. Nowadays `querySelector` is almost universally available, but it suffers from the same basic issue - it's browser-dependent. The other issue is that `querySelector` is not extendable. It's easy to write your own extensions for Sizzle, on the other hand. More details and more history are in the duplicate thread. – Tomalak Jul 16 '20 at 10:44