Friday, December 17, 2010

How to avoid Conflict in jQuery

Many JavaScript libraries use $ as a function or variable name, just as jQuery does. In jQuery's case, $ is just an alias for jQuery, so all functionality is available without using $. If we need to use another JavaScript library alongside jQuery, we can return control of $ back to the other library with a call to $.noConflict():



Creates a different alias instead of jQuery to use in the rest of the script.



var $j = jQuery.noConflict();
// Do something with jQuery
$j("div p").hide();

// Do something with another library's $()
$("content").style.display = 'none';

0 comments:

Post a Comment