Copyright © tutorialspoint.com
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 $.
Run $.noConflict() method to give control of the $ variable back to whichever library first implemented it. This helps 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 $.noConflict(); // 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 $.noConflict(); jQuery(document).ready(function($) { // Code that uses jQuery's $ can follow here. }); // Code that uses other library's $ can follow here. DOM Element |
Copyright © tutorialspoint.com