jQuery.noConflict([removeAll]) (since 1.0) gives the global $ name back to whatever owned it before jQuery loaded. jQuery itself stays available as jQuery unless you pass true. The method returns the jQuery object so you can keep an alias.
Syntax
Start with these common calls. Keep them short and readable.
jQuery
// Give $ back to the other library
jQuery.noConflict();
// Still use jQuery by full name
jQuery("div p").hide();
// Or keep a private alias
var $jq = jQuery.noConflict();
$jq("div p").hide();
// Or use $ safely inside ready / an IIFE
jQuery(function ($) {
// $ is jQuery here
});
Call
What it does
removeAll
true also releases global jQuery
Return value
The jQuery object (save as an alias)
Call timing
After jQuery loads, before other-lib $ code
Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.
Parameters
Parameter
Description
Step 1
Load the other library that needs $ (if any), then load jQuery.
Step 2
Call jQuery.noConflict() so global $ returns to the other library.
Step 3
Use jQuery(...), a saved alias, ready’s $ argument, or an IIFE.
Return Value
Return Value
Description
jQuery object
Most setters and traversing helpers return the jQuery collection so you can chain more methods.
jQuery Examples
Example 1 — Restore $, Use jQuery
Official pattern: give $ back, then call jQuery by name.
jQuery
jQuery.noConflict();
// jQuery code
jQuery("div p").hide();
// Other library can use $ again
// $("content")…
Paragraph hidden with jQuery(...)
Global $ belongs to the other library again
How It Works
Release.noConflict() restores the previous global $.
Keep jQuery. The jQuery global name still works.
Select. Call methods as jQuery(...).
Example 2 — Safe $ Inside Ready
Official pattern: after noConflict, the ready callback receives jQuery as $.
jQuery
jQuery.noConflict();
jQuery(document).ready(function ($) {
// $ is jQuery here
$("p").text("Styled inside ready with local $");
});
// Outside, global $ is the other library
Styled inside ready with local $
Outside ready, global $ is still the other library
How It Works
Release. Global $ is no longer jQuery.
Ready. jQuery passes itself into the callback as $.
Local. Inside that function, $ is safe and private.
Example 3 — IIFE Alias
Official pattern: wrap jQuery code in (function ($) { … })(jQuery).
jQuery
jQuery.noConflict();
(function ($) {
$(function () {
$("li").text(function (i, t) {
return t + " ✓";
});
});
})(jQuery);
// Other code using $ as the other library
One ✓
Two ✓
IIFE $ is jQuery; global $ is the other library
How It Works
Pass. The IIFE receives jQuery as the parameter $.
Scope. Inside the function, $ always means jQuery.
Ready. Nested $(function () { … }) still works.
Frequently Asked Questions
jQuery.noConflict() returns control of the global $ variable to whatever owned it before jQuery loaded. jQuery remains available as the global jQuery identifier. Optionally pass true (removeAll) to also release the jQuery global name. Available since jQuery 1.0.
After a plain noConflict() call, the global $ is no longer jQuery. You can still write jQuery("div"), assign var $jq = jQuery.noConflict(), or use the ready alias: jQuery(function($){ /* $ is jQuery here */ }).
Passing true removes both $ and jQuery from the global scope (restoring prior owners). The method returns the jQuery object so you can keep a local reference: var jq = jQuery.noConflict(true). Rarely needed — and it can break plugins that expect window.jQuery.
Call it after jQuery loads and before code that needs the other library’s $. Typical order: load other lib, load jQuery, call jQuery.noConflict(), then write jQuery-based code with jQuery or a saved alias.
No. Prefer one jQuery version. If you must, load both scripts, then call noConflict(true) on the second version to restore the first as the global jQuery/$.
Use jQuery(function($){ ... }), wrap code in (function($){ ... })(jQuery), or save the return value: var $jq = jQuery.noConflict().