English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

jQuery $ .noConflict() method

jQuery Miscellaneous Methods

The jQuery $ .noConflict() method releases jQuery's specification of the $ variable so that other scripts can use it.

This method can also be used to specify a new custom name for the jQuery variable.

As you know, jQuery uses the dollar sign ($) as a shortcut or alias for jQuery.

$, like jQuery, is used as a function or variable name by many JavaScript libraries.

If two different libraries use the same shortcut, one of them may stop working.

Fortunately, jQuery provides a special $ .noConflict() method to handle this situation.

Syntax:

$.noConflict(removeAll)

Example

Of course, you can still use jQuery, just write the full name instead of the shortcut:

$.noConflict();
jQuery(document).ready(function(){
  jQuery("button").click(function(){
    jQuery("p").text("jQuery working perfectly!!!");
  });
});
Test and see‹/›

The following example creates an alias instead of using jQuery as a shortcut in the rest of the script:

let jq = $.noConflict();
jq(document).ready(function(){
  jq("button").click(function(){
    jq("p").slideToggle();
  });
});
Test and see‹/›

Parameter Value

ParameterDescription
removeAllAn optional boolean value indicating whether to remove all jQuery variables from the global scope (including jQuery itself)

jQuery Miscellaneous Methods