I’ve come across a problem where I have multiple plugins conflicting over their version of jquery. Now I have searched google, and I know that you should ultimately just use one version of jquery and update your code to that version of jquery. However, out of curiousity, I’m interested in knowing what happens when you do the following:
<include latest jquery>
<include script that uses jquery> <---and this jquery code is called back or triggered in some event handler function.. what happens then? what jquery $ version is used? the last jquery object that was added (the 'yet another version of jquery' )
<include some other version of jquery>
<include yet another version of jquery>
what version of jquery is used? and why? what exactly happens, how does the loading and execution of each script occur? does it just call the latest jquery’s $ alias? thank you for your help.
It will depend. The scripts will be loaded and executed in order. Any code that is executed immediately in your intermediate script will use the jQuery found in the top script. Any code that is deferred till later (for instance function definitions that will be called by another script, or that are nested within event handlers) will use the final version loaded.
If that is not desired behavior you can use jQuery.noConflict(), although that may potentially involve modifying the plugins you’re using to use the correct version.