jQuery MISC

By ukmodak | March 31st 2024 10:31:18 AM | viewed 1115 times

jQuery - The noConflict()

As you already know; jQuery uses the $ sign as a shortcut for jQuery. There are many other popular JavaScript frameworks like: Angular, Backbone, Ember, Knockout, and more.

If two different frameworks are using the same shortcut, one of them might stop working.

The jQuery team have already thought about this, and implemented the noConflict() method.

Example

$.noConflict();
jQuery(document).ready(function(){
  jQuery("button").click(function(){
    jQuery("p").text("jQuery is still working!");
  });
});


$.noConflict();
jQuery(document).ready(function($){
  $("button").click(function(){
    $("p").text("jQuery is still working!");
  });
});
bONEandALL
Visitor

Total : 27273

Today :9

Today Visit Country :

  • United States
  • Sweden
  • Singapore
  • Russia