0

I'm doing some testing for my company re jQuery versions (we have a lot of old code which does weird things with new versions). I want to set up a way to dynamically choose a jQuery version while on the page, without reloading the whole page.

For example:

  • page loads with version 6.2.0 by default
  • there's a feature on the page that happens after a click event
  • I want to switch to different versions before this click in order to try out each one
  • if I want to try it with version 11.1.0, I select that from a dropdown and some magic happens that unloads 6.2.0 and loads 11.1.0

Is this magic possible?

sveti petar
  • 3,637
  • 13
  • 67
  • 144
  • 2
    I think the real magic here is that you're up to versions 6 and 11 of [jQuery](https://code.jquery.com/jquery/)! :) Anyways, try reading about jQuery's [noconflict](http://stackoverflow.com/questions/1566595/can-i-use-multiple-versions-of-jquery-on-the-same-page). You can include both versions of jQuery and modify your code so that individual sections know which version to use. – Tyler Roper Mar 24 '17 at 17:22
  • Possible, yes, you simply switch what version of jquery is stored in `window.$` and `window.jQuery`, and make sure all of your code references the globally stored `$` and `jQuery`. simple. – Kevin B Mar 24 '17 at 17:26
  • @Santi Yes, this is a problem from 2024 :P – sveti petar Mar 24 '17 at 17:42
  • It's worth noting that this will make all of your events stale. Do you not want the page to **visually** reload or do you actually need the page in its existing state? Have you considered loading jQuery in an invisible iFrame and having it act on elements there? – Sandy Gifford Mar 24 '17 at 17:56
  • @Sandy this is just for testing, we have a lot of buttons and sliders that do different things and it's a huge mess. The goal is to adapt everything to the last jquery version, this is just to easily categorize which feature needa which veraion. I know, I know...I didn't write this thing, a bunch of different people did. I'm trying to untangle it now. – sveti petar Mar 24 '17 at 17:58
  • @jovan Yeah, I know it's not ideal, but I'd have you dropdown change the source of an `iframe` (visible or not). The controls and what-not will reload, but at least the selecting interface won't. – Sandy Gifford Mar 24 '17 at 18:01

0 Answers0