jQuery .noConflict() Method

Beginner
⏱️ 11 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Global aliases

What You’ll Learn

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

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.

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.

📝 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();

⚡ Quick Reference

GoalCode
Free global $jQuery.noConflict();
Keep a short aliasvar j = jQuery.noConflict();
Local $ in readyjQuery(function($){ /* jQuery $ */ });
IIFE alias(function($){ ... })(jQuery);
Release $ and jQueryvar 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

📋 noConflict() vs noConflict(true) vs IIFE

noConflict()noConflict(true)IIFE (function($){})(jQuery)
Global $RestoredRestoredUnchanged (you never took it)
Global jQueryKeptRestoredKept
Best forShare page with Prototype etc.Two jQuery builds / full releasePlugin isolation without releasing globals

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";
Try It Yourself

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.
Try It Yourself

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
Try It Yourself

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";
Try It Yourself

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
Try It Yourself

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.

🚀 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 appsapp.$ = 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.

📝 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 noConflict after 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.

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 Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
noConflict Universal

Bottom line: Use it whenever another library (or your own code) needs the global $ name.

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.

Next up: jQuery.trim().

💡 Best Practices

✅ Do

  • Call noConflict() once, early, after jQuery loads
  • 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

Key Takeaways

Knowledge Unlocked

Five things to remember about noConflict

Share the page with other $ users safely.

5
Core concepts
JQ 02

Keeps

jQuery

Default
03

Returns

Alias

Capture
() 04

ready($)

Local

Safe
T 05

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.

Next: jQuery.trim() Method

Remove leading and trailing whitespace from strings the jQuery way.

jQuery.trim() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful