jQuery - noConflict()


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 the functionality is available without using $.

Run $.noConflict() method to give control of the $ variable back to whichever library first implemented it. This helps us to make sure that jQuery doesn't conflict with the $ object of other libraries.

Here is simple way of avoiding any conflict −

// Import other Library
// Import jQuery Library
// Code that uses other library's $ can follow here.

This technique is especially effective in conjunction with the .ready() method's ability to alias the jQuery object, as within the .ready() we can use $ if we wish without fear of conflicts later −

// Import other library
// Import jQuery
jQuery(document).ready(function($) {
   // Code that uses jQuery's $ can follow here.
// Code that uses other library's $ can follow here.


E-Books Store