Free Premium Iphone Denati Wordpress Theme

Nulla facilisi. Curabitur lorem turpis, cursus id aliquam non, molestie in nulla. Nulla eleifend arcu in tellus facilisis bibendum. Integer id turpis et neque placerat interdum! Ut rutrum velit a dui malesuada vitae dictum turpis sagittis. Sed malesuada neque ut eros ultricies accumsan. Nulla facilisi. Curabitur lorem turpis, cursus id aliquam non, molestie in nulla. Nulla eleifend arcu in tellus facilisis bibendum. Integer id turpis et neque placerat interdum!

Using multiple versions of jQuery in a single project.

I had an interesting issue where one script I was using wouldn’t work above 1.2.8 but for the remainder of the project I wanted to use the up to date jQuery version.

After starting to rebuild the contribution and deciding against it I chose to try and setup multiple jQuery versions working alongside each other! It turned out to be quick and easy so read on if you want to find out how:

Much like preparing jQuery for noConflict with other Libraries you can use this technique to run multiple version of jQuery too!

Regular preparation for noConflict:

<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
   $.noConflict();
   jQuery(document).ready(function($) {
      // Code that uses jQuery's $ can follow here.
   });
   // Code that uses other library's $ can follow here.
</script>

Preparation using noConflict to use two versions of jQuery:

<script type="text/javascript" src="jquery-1.2.8.js"></script>
<script>
   $jQuery_128 = $.noConflict(true);
</script>
<script>
   // Link all your Js you want 128 linked to here!
   // Change your jQuery objects to "$jQuery_128"
   // eg:
   $jQuery_128(document).ready(function() {
      // You need to use the "$jQuery_128" namespace herein
   });
</script>
<script type="text/javascript" src="jquery-latest.js"></script>
// Code that uses latest library follow on here!

Because I set the [removeAll] all as true this disables the default namespaces:

$jQuery_128 = jQuery.noConflict( [removeAll] )

This mean that the “$” and “jQuery” namespaces no longer work for version 1.2.8 [as per example above] so this always requires the use of the newly assigned namespace “$jQuery_128″. Thus the latest version of jQuery running alongside this one can use the “$” and “jQuery” namespaces without problem.

Eg:

$j_128(document).ready(function() {
   alert('We are using jQuery 1.2.8');
});

That should just about do it! Run old alongside new!
Give it a whirl.

Useful reference: http://api.jquery.com/jQuery.noConflict/

About the Author

Related Posts

Leave a Reply