In usercript, is there any advantage to using querySelector () vs jQuery $ ()?

Is there any advantage to using querySelector()vs jQuery $()in usercript? I want the script to work in all major browsers that support scripts, so I'm especially interested in cross-browser compatibility.

I started to think about this because I noticed that the excellent Reddit Enhancement Suite does a great job of jQuery as a dependency, but basically sticks querySelector()to selecting elements and other basic JavaScript methods for manipulating the DOM.

Is it just a matter of taste, or is there a reason to use jQuery at least?

+5
source share
2 answers

The only reason to use querySelector()or querySelectorAll()is because you are not using jQuery. JQuery selectors are more powerful and most likely consistently work in browsers than advanced CSS selectors.

Nevertheless, including jQuery can uselessly complicate simple scripts. Most browsers require Script Injection, which defeats the sandbox, creates potential conflicts and makes your Script dependent on a third-party server.
Here is a cross-browser way to enable jQuery that minimizes conflicts. And if the browser supports local copies of jQuery, it does not require the third-party server to always be up / fast.

Script , jQuery , querySelector(). Script script, 99% .

Script jQuery , jQuery .

, , DOM, jQuery . Firefox + Greasemonkey Chrome + Tampermonkey jQuery, @require it.

+3

querySelector , jQuery $() .

+1

All Articles