Reputation: 25586
Similar question for reference: How do I run different versions of jQuery on the same page?
I have a situation where I have my own version of jQuery(1.4.2), with all sorts of custom functions defined. This version of jQuery is loaded before a third party script, which loads its own version of jQuery (1.4.3), and when this script is loaded it somehow destroys all the custom functions I had. The third party script uses noconflict after jQuery is loaded. Because of the noconflict code, I assume the problem would be fixed if I could load the third party script before anything else, however my environment is such that I cannot guarantee this, however I can run some custom javascript before and/or after loading the script if I load it dynamically.
What I am wondering is if there is some way I can save/restore/protect my own version of jQuery so that the custom methods will be accessible after the third party script runs?
Upvotes: 1
Views: 781
Reputation: 47988
If you can run custom code before and after this script is loaded I believe this will do it:
var $myJQ = jQuery.noConflict();
// Load the other script. It should move itself away from the $ and jQuery variables
// if it properly calls noConflict.
var $ = $myJQ;
I believe gets you to what you're after.
Upvotes: 2
Reputation: 3069
From http://blog.nemikor.com/2009/10/03/using-multiple-versions-of-jquery/
<!-- load jQuery 1.1.3 -->
<script type="text/javascript" src="http://code.jquery.com/jquery-1.1.3.js"></script>
<script type="text/javascript" src="jquery.dimensions.min.js"></script>
<!-- revert global jQuery and $ variables and store jQuery in a new variable -->
<script type="text/javascript">
var jQuery_1_1_3 = $.noConflict(true);
</script>
<!-- load jQuery 1.3.2 -->
<script type="text/javascript" src="http://code.jquery.com/jquery-1.3.2.js"></script>
<!-- revert global jQuery and $ variables and store jQuery in a new variable -->
<script type="text/javascript">
var jQuery_1_3_2 = $.noConflict(true);
</script>
and then
jQuery_1_1_3('<button>Use jQuery 1.1.3</button>')
.click(function() {
alert('Top: ' + jQuery_1_1_3(this).offset().top + '\n' +
'jQuery: ' + jQuery_1_1_3.fn.jquery);
})
.appendTo('body');
Upvotes: 0