jQuery noConflict() is used to avoid conflicts between jQuery and other JavaScript libraries that use the $ symbol. It releases the $ shortcut so that other libraries can use it safely.
$noConflict() restores control of $When multiple libraries use the same global variable ($), JavaScript conflicts can occur. The jQuery.noConflict() method prevents this by releasing the $ identifier.
// Release the $ symbol used by jQuery
jQuery.noConflict();
// Assign jQuery to a new variable
var jq = jQuery.noConflict();
// Use jq instead of $
jq(document).ready(function() {
jq("p").css("color", "blue");
});
$ symbol is freed for other librariesjq variableClick the buttons below to see how noConflict() works. We will "hijack" the $ variable with a fake library and see if jQuery can still run.
// Simulate another library using $
var $ = function() {
return "I am a different library!";
};
// Use jQuery safely with noConflict
var jq = jQuery.noConflict();
jq(function() {
jq("#status-display").text("jQuery is working using 'jq' alias!");
});
noConflict() after loading jQuery$document.readynoConflict() to jQuery