Tuesday 3 July 2012

Using multiple version of jQuery on same page

,
During working on project you might have encounter this problem of jquery.
There is problem coming when you are using jquery1.6 in project and you have to use jquery plugin which require jquery1.4 and it is incompatible with 1.6. So what you do remove that plugin or change your jquery  version.There is also another solution which is define below.You can use jQuery of different version easily with this following step.

<script type="text/javascript" src="jquery1.4.2.js">
</script>  
<script type="text/javascript">  
   var jq_4 = jQuery.noConflict();  
</script>  
<script type="text/javascript" src="jquery1.6.js">
</script>  
<script type="text/javascript">  
   var jq_6 = jQuery.noConflict();  
</script>  
<script type="text/javascript" src="jquery1.7.js">
</script>  
<script type="text/javascript">  
   var jq_7 = jQuery.noConflict();  
</script>  
<script type="text/javascript">  
   // You can use different instance of jquery library.   
   jq_4(document).ready(function () {  
     // so now you can use jquery jq variable instead of $ .   
     jq_4("div").hide();  
   });  
   jq_7(document).ready(function () {  
     // so now you can use jquery jq variable instead of $ .   
     jq_7("div").hide();  
   });  
</script>  

2 comments:

  1. In my case I have another plugin which is dependent of say jquery.1.4 but in that plugin $ is used everywhere.
    So do I need to replace $ with new variable for all occurrences of $ in plugin?

    ReplyDelete
    Replies
    1. it depend on how your plugin is called for example in above case for jQuery1.4 I am using cycle plugin than I will call it by something like this jq_4('#shuffle').cycle();

      Delete