JQuery $naming conflict how to resolve

  • 2020-03-30 01:24:37
  • OfStack

Other JavaScript frameworks include MooTools, Backbone, Sammy, Cappuccino, Knockout, JavaScript MVC, Google Web Toolkit, Google Closure, Ember, Batman, and Ext JS.

Some of these frameworks also use the $symbol as a shorthand (like jQuery), and if you're using two different frameworks that are using the same shorthand symbol, it can cause the script to stop running.

JQuery's team took this into account and implemented the noConflict () method.

The instance

You can also create your own abbreviations. NoConflict () returns a reference to jQuery, which you can store in a variable for later use. Here's an example:
 
var jq = $.noConflict(); 
jq(document).ready(function(){ 
jq("button").click(function(){ 
jq("p").text("jQuery  Still running! "); 
}); 
}); 

Related articles: