jQuery.noConflict() gives the global $ name back to another library (or your own code) while jQuery keeps working as jQuery. This tutorial covers the optional removeAll flag, custom aliases, the .ready()$ parameter trick, IIFE wrappers, and when (not) to load two jQuery versions.
01
Free $
Restore alias
02
jQuery()
Still works
03
Custom
Alias var
04
ready($)
Local $
05
removeAll
.noConflict(true)
06
Since 1.0
Core API
Fundamentals
Introduction
Many libraries use $ as a shortcut — jQuery, Prototype, and custom helpers alike. When two of them load on one page, the last one to assign window.$ wins and the other breaks.
Since jQuery 1.0, jQuery.noConflict() restores the previous owner of $. jQuery itself stays on window.jQuery (unless you pass true). You keep full jQuery power without fighting over a one-character name.
Pair this with .ready() so callbacks can still receive $ as a local parameter. Browse more helpers in the Utilities hub.
Concept
Understanding the jQuery.noConflict() Method
When jQuery starts, it saves any existing window.$ (and window.jQuery). Calling jQuery.noConflict() puts that saved $ back and returns the jQuery object so you can keep a reference.
With jQuery.noConflict(true), both $ and jQuery are restored to their previous owners. Capture the return value if you still need that jQuery build.
💡
Beginner Tip
After jQuery.noConflict(), write jQuery(".box") or var $j = jQuery.noConflict(); $j(".box"). The short global $ may belong to someone else again.
Foundation
📝 Syntax
Signature (jQuery 1.0+):
jQuery
jQuery.noConflict( [ removeAll ] )
Parameters
removeAll (optional Boolean) — if true, also release the global jQuery name (restore the previous owner). Default behaves like false: only $ is restored.
Return value
Object (the jQuery function) — so you can assign a private alias immediately.
Minimal pattern
jQuery
jQuery.noConflict();
// Other library can use $ again here
jQuery( "div p" ).hide();
Cheat Sheet
⚡ Quick Reference
Goal
Code
Free global $
jQuery.noConflict();
Keep a short alias
var j = jQuery.noConflict();
Local $ in ready
jQuery(function($){ /* jQuery $ */ });
IIFE alias
(function($){ ... })(jQuery);
Release $ and jQuery
var jq = jQuery.noConflict(true);
noConflict()
free $
Restores previous window.$; jQuery global remains
noConflict(true)
removeAll
Also restores previous window.jQuery
Returns
jQuery
Capture as var j = jQuery.noConflict()
ready($)
local $
Safe $ inside the ready callback only
Compare
📋 noConflict() vs noConflict(true) vs IIFE
noConflict()
noConflict(true)
IIFE (function($){})(jQuery)
Global $
Restored
Restored
Unchanged (you never took it)
Global jQuery
Kept
Restored
Kept
Best for
Share page with Prototype etc.
Two jQuery builds / full release
Plugin isolation without releasing globals
Hands-On
Examples Gallery
Examples follow the official jQuery API patterns. Use View Output or Try It Yourself to explore each case.
📚 Getting Started
Official patterns for freeing $ while keeping jQuery usable.
Example 1 — Official Pattern: Restore $, Use jQuery
Call noConflict(), then use the full jQuery name for selectors.
jQuery
jQuery.noConflict();
// Do something with jQuery
jQuery( "div p" ).hide();
// Do something with another library's $()
// $( "content" ).style.display = "none";
typeof window.$ may no longer be "function" (jQuery)
jQuery("div p") still hides paragraphs
$ is free for the other library
How It Works
jQuery restores the prior $. Your script switches to the unambiguous jQuery identifier. The commented line shows where Prototype-style (or other) $ code would run safely afterward.
Example 2 — Official Pattern: $ Inside .ready()
After noConflict(), pass a function to jQuery(document).ready (or jQuery(fn)) and name the argument $.
jQuery
jQuery.noConflict();
jQuery( document ).ready(function( $ ) {
// Code that uses jQuery's $ can follow here.
$( "p" ).addClass( "ready" );
});
// Code that uses other library's $ can follow here.
Inside ready: $ is jQuery
Outside: global $ is not jQuery (after noConflict)
Best of both worlds for page scripts
How It Works
jQuery invokes your ready handler with the jQuery function as the first argument. Naming that parameter $ gives you the familiar shortcut only inside that function — without reclaiming the global $.
📈 Practical Patterns
IIFEs, custom aliases, and removeAll.
Example 3 — Official Pattern: IIFE Wraps $
Pass jQuery into an immediately invoked function so the whole block can use $.
jQuery
jQuery.noConflict();
(function( $ ) {
$(function() {
// More code using $ as alias to jQuery
$( "li" ).addClass( "ok" );
});
})(jQuery);
// Other code using $ as an alias to the other library
Inside IIFE: $ === jQuery
Outside IIFE: $ is the other library (or undefined)
Common pattern for plugins and page modules
How It Works
The parameter $ shadows any global $. Inside the IIFE you write normal jQuery code; outside, the other library keeps the global name. Works well for plugins that do not need another library’s $ internally.
Example 4 — Official Pattern: Custom Alias
Store the return value under any name you like (here j).
jQuery
var j = jQuery.noConflict();
// Do something with jQuery
j( "div p" ).hide();
// Do something with another library's $()
// $( "content" ).style.display = "none";
j === jQuery function
j("div p") works
Global $ restored for other code
How It Works
noConflict() returns jQuery. Assigning it to j (or $j, jq, …) gives a short, conflict-free alias for the rest of your file.
Example 5 — Official Pattern: noConflict(true) / New Namespace
Pass true to release both $ and jQuery, keeping only your captured reference.
jQuery
var dom = {};
dom.query = jQuery.noConflict( true );
// Do something with the new jQuery
dom.query( "div p" ).hide();
// window.jQuery / window.$ restored to previous owners
dom.query is your jQuery reference
typeof window.jQuery may be "undefined" (if nothing else claimed it)
Plugins expecting global jQuery may break — use carefully
How It Works
removeAll: true clears jQuery’s globals. You must hang onto the return value. The official docs also show loading two jQuery versions and calling noConflict(true) on the second to restore the first — avoid that in new apps.
Applications
🚀 Common Use Cases
jQuery + Prototype — classic conflict; free $ for Prototype after jQuery loads.
CMS / WordPress themes — many stacks already call jQuery.noConflict() and expect jQuery in theme scripts.
Custom $ helpers — your page defines $ for DOM shortcuts; jQuery must not overwrite it permanently.
Plugin bundles — wrap plugin code in (function($){ ... })(jQuery) after noConflict.
Migration sandboxes — rare dual-jQuery pages during upgrades (prefer one version).
Namespaced apps — app.$ = jQuery.noConflict(true) when you own the whole page API.
🧠 How noConflict Restores Names
1
jQuery loads
It saves any previous $ / jQuery and takes those globals.
Init
2
You call noConflict
Saved owners are put back on window.
Restore
3
Keep a reference
Use jQuery, a custom alias, ready($), or an IIFE.
Alias
4
✓
Both libraries coexist
Other code uses global $; your jQuery code uses its alias.
Important
📝 Notes
Available since jQuery 1.0; still present in modern jQuery 3.x / 4.x.
$ is only an alias — every API works as jQuery(...).
Call noConflictafter jQuery loads and before scripts that need the other $.
noConflict(true) can break plugins that require a global jQuery.
Loading two jQuery versions is discouraged; use only for temporary migrations.
Not the same as jQuery.sub() (removed API for copying jQuery).
Document-ready and IIFE patterns let you keep writing $ locally without globals.
Compatibility
Browser Support
jQuery.noConflict() has been part of jQuery since 1.0+. It works in every browser supported by your jQuery build — including modern evergreen browsers with jQuery 3.x and 4.x.
✓ jQuery 1.0+
jQuery.noConflict()
Stable global-alias management across jQuery 1.x–4.x. No browser-specific polyfills — jQuery handles $ / jQuery restoration itself.
100%With jQuery loaded
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
noConflictUniversal
Bottom line: Use it whenever another library (or your own code) needs the global $ name.
Wrap Up
Conclusion
jQuery.noConflict() solves a naming problem, not a feature gap: give $ back, keep coding with jQuery or a private alias, and optionally nest $ inside ready or an IIFE.
Prefer jQuery(function($){ ... }) or an IIFE for local $
Document which alias your team uses (jQuery, $j, …)
Keep a single jQuery version on the page when possible
Test third-party plugins after noConflict(true)
❌ Don’t
Assume global $ is still jQuery after noConflict
Load two jQuerys unless you have a migration plan
Call noConflict(true) without saving the return value
Confuse noConflict with sandboxing or $.sub()
Mix aliased and global jQuery styles randomly in one file
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about noConflict
Share the page with other $ users safely.
5
Core concepts
$01
Frees
$
Global
JQ02
Keeps
jQuery
Default
↪03
Returns
Alias
Capture
()04
ready($)
Local
Safe
T05
true
removeAll
Advanced
❓ Frequently Asked Questions
jQuery.noConflict() returns control of the global $ variable to whatever owned it before jQuery loaded (often another library). 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 document-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). Use this mainly when loading two jQuery versions — it is rarely needed otherwise and 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. The official docs show it for migration edge cases. 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/$.
noConflict only manages global names ($ and optionally jQuery). jQuery.sub() (removed in 1.9) created a copy of the API for private methods — unrelated to sharing $ with Prototype or other libraries.
Did you know?
Before jQuery popularized $, Prototype.js already used it heavily. noConflict was designed so both libraries could share a page during the mid-2000s Ajax boom. Today ES modules reduce global clashes, but CMS ecosystems and legacy widgets still rely on this one-line peace treaty.