Tuesday 22 March 2011

JQuery conflict when using different javascript libraries

If your application is using both JQuery and Prototype libraries(ex: External js file which are using $(.) to get the objects). Both are operating with $() to access the objects and do the client side logic. But, the $() is getting conflicted between JQuery and Prototype libraries.

The solution to resolve the conflict:

If you are using JQuery in your applications, the best practice is declare the Jquery global instance variable and then start using that variable instead of directly use the $().

For example,
var $j = jQuery.noConflict(); 
// Use jQuery via $j(...) instead of $(...)
$j(document).ready(function(){ 
$j("#someId").hide(); 
}); 

No comments:

Post a Comment