Tuesday, January 20, 2015

Multiple versions of jQuery on the same page?

Multiple versions of jQuery on the same page?

Is it possible to handle conflicts between 2 versions of jQuery loaded in the same page? Assume that these lines of code:

----------------------------------------------------------------------------
<script type="text/javascript" src="jquery-1.1.3.js"></script>              
<script type="text/javascript" src="jquery-1.4.2.js"></script>              
                                                                            
--------------------------------------------------------------------------- 

solution 

use $.noConflict(true);

<!-- load jQuery 1.1.3 -->                                                       
<script type="text/javascript" src="http://example.com/jquery-1.1.3.js"></script>
<script type="text/javascript">                                                  
var jQuery_1_1_3 = $.noConflict(true);                                           
</script>                                                                        

<!-- load jQuery 1.3.2 -->                                                       
<script type="text/javascript" src="http://example.com/jquery-1.3.2.js"></script>
<script type="text/javascript">                                                  
var jQuery_1_3_2 = $.noConflict(true);                                           
</script>                                                                        

Then, instead of $('#selector').function();,                                     
 you'd do jQuery_1_3_2('#selector').function(); or jQuery_1_1_3('#selector').function();.


enjoy :)                                                                                

No comments:

Post a Comment

How to Host a Laravel Project on Hostinger’s hPanel: A Step-by-Step Guide

How to Host a Laravel Project on Hostinger’s hPanel: A Step-by-Step Guide If you're looking to host a Laravel project on Hostinger’s hPa...