Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

278
Views
In a userscript/greasemonkey, how do you use a newer version of jQuery when the website already uses an older version?

I'm trying to write a userscript for a website that is already using an ancient version of jQuery. If I @require a modern version in the userscript, I get a console error about how a field named exists doesn't exist. Since these two versions of jQuery are incompatible, is there any way to use them both without them conflicting?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Maybe there's an even better solution than this, but here's what I've come up with: @require jQuery the way you'd normally want, then at the end of your script, put a $.noConflict();. As some of your userscript functions may need to use the latest version, it may not be enough to put $.noConflict(); as the last line. To avoid thinking about that possibility, you can write your script like this:

...
// @require https://code.jquery.com/jquery-3.6.0.min.js
// ==/UserScript==

((jQueryAsAParameter) => {
  // use jQueryAsAParameter in here, because $ may refer to the old version
  ...
})($);

$.noConflict();

This is called an IIFE if you want to learn more. The above is kind of weird. I wrote it that way to make the next example easier to understand. This achieves the same effect, but in my opinion, it's more idiomatic.

...
// @require https://code.jquery.com/jquery-3.6.0.min.js
// ==/UserScript==

(($) => {
  ...
})($);

$.noConflict();
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!