My company has purchased a product that renders an ASP.NET control on the page. This control uses jQuery 1.2.3 and adds a script tag to the page to reference it. The developers of the control will not support use of the control if it modified in any way (including modification to reference a different version of jQuery).
I'm about to start development of my own control and would like to use the features and speed improvements of jQuery 1.3. Both of these controls will need to exist on the same page.
How can I allow the purchased control to use jQuery 1.2.3 and new custom development to use jQuery 1.3? Also out of curiosity, what if we were to use an additional control that needed to reference yet another version of jQuery?
You can achieve this by running your version of jQuery in no-conflict mode. "No conflict" mode is the typical solution to get jQuery working on a page with other frameworks like prototype, and can be also be used here as it essentially namespaces each version of jQuery which you load.
This change will mean that any of the jQuery stuff you want to use will need to be called using
jq13
rather than$
, e.g.It's not an ideal situation to have the two versions running on the same page, but if you've no alternative, then the above method should allow you to use two differing versions at once.
If you needed to add another version of jQuery, you could expand on the above:
The variables
jq13
andjq131
would each be used for the version-specific features you require.It's important that the jQuery used by the original developer is loaded last - the original developer likely wrote their code under the assumption that
$()
would be using their jQuery version. If you load another version after theirs, the$
will be "grabbed" by the last version you load, which would mean the original developer's code running on the latest library version, rendering thenoConflicts
somewhat redundant!As said ConroyP you can do this with
jQuery.noConflict
but don't forgetvar
when declaring variable. Like this.You can connect all $'s to jq13 by adding (jq13) after function's
})
. like thisIn the second version declare a variable as $.noConflict(true). And use the declared variable in place of $ used in the jquery code. Please check the below code : This code is used after the declaration of second versions of jquery:
make it false to work
It seems like the order doesn't matter... for example: http://gist.github.com/136686. The console output is at the top and all the versions seem to be in the right places.