jQuery noConflict() Method

Beginner
7 min read
Updated: Oct 2026
5 examples
Live preview

What Is jQuery.noConflict()?

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.

Remember
// 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
});
NeedUse
Free global $jQuery.noConflict()
Keep a short aliasvar j = jQuery.noConflict()
Use $ inside readyjQuery(function ($) { … })
IIFE scope(function ($) { … })(jQuery)
Free $ and jQueryjQuery.noConflict(true) ⚠

How to Use noConflict()

Load order matters. Free $, then keep a clear way to call jQuery.

  1. Load the other library that needs $ (if any), then load jQuery.
  2. Call jQuery.noConflict() so global $ returns to the other library.
  3. Use jQuery(...), a saved alias, ready’s $ argument, or an IIFE.
  4. Only pass true when you must also remove the global jQuery name.
  5. Avoid loading two jQuery versions unless you have a rare migration need.
PieceRequired?Role
removeAllOptionaltrue also releases global jQuery
Return valueUsefulThe jQuery object (save as an alias)
Call timingYesAfter jQuery loads, before other-lib $ code

Pseudocode

Pseudocode
other library may own window.$

jQuery loads
    → saves previous $
    → sets window.$ = jQuery
    → sets window.jQuery = jQuery

call jQuery.noConflict()
    → restore previous window.$
    → keep window.jQuery
    → return jQuery object

call jQuery.noConflict(true)
    → restore previous $ and jQuery
    → return jQuery object (capture it!)

use jQuery via:
    jQuery(...)
    savedAlias(...)
    jQuery(function ($) { ... })
    (function ($) { ... })(jQuery)

Cheat Sheet

Keep these patterns handy when sharing a page with another $ library.

TopicDetail
BasicjQuery.noConflict()
removeAlljQuery.noConflict(true)
ReturnsjQuery object (alias-friendly)
Since1.0
Ready aliasjQuery(function ($) { … })
IIFE alias(function ($) { … })(jQuery)
Custom namevar j = jQuery.noConflict()
Two versions?Not recommended — prefer one build

Live Preview

This page needs global jQuery, so the demo explains patterns without calling noConflict() on the site. Use Try It Yourself for a real release of $.

Safe preview only — real noConflict() demos live in the Try It editors.

Result
Ready — pick an action and click Run.

jQuery Examples

Short, copy-ready patterns from the official API. Use Try It Yourself for a live editor.

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

How It Works

  1. Release. noConflict() restores the previous global $.
  2. Keep jQuery. The jQuery global name still works.
  3. Select. Call methods as jQuery(...).
  4. Share. Other code can use $ without fighting 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
Try It Yourself

How It Works

  1. Release. Global $ is no longer jQuery.
  2. Ready. jQuery passes itself into the callback as $.
  3. Local. Inside that function, $ is safe and private.
  4. Outside. Code after ready still sees the other library’s $.

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

How It Works

  1. Pass. The IIFE receives jQuery as the parameter $.
  2. Scope. Inside the function, $ always means jQuery.
  3. Ready. Nested $(function () { … }) still works.
  4. Outside. Global $ stays free for the other library.

Example 4 — Custom Alias

Official pattern: save the return value as your own short name.

jQuery
var j = jQuery.noConflict();

// Do something with jQuery
j("div p").hide();

// Do something with another library's $()
// $("content")…
Try It Yourself

How It Works

  1. Capture. noConflict() returns the jQuery function.
  2. Alias. Store it in j (or any name you like).
  3. Call. Use j(...) instead of $(...).
  4. Free $. The global dollar sign is available elsewhere.

Example 5 — noConflict(true)

Official pattern: move jQuery into your own namespace and clear both globals.

jQuery
var dom = {};
dom.query = jQuery.noConflict(true);

// New reference
dom.query("div p").hide();

// window.$ and window.jQuery are restored / cleared
// Plugins that need global jQuery may break
Try It Yourself

How It Works

  1. Capture first. Save the return value before globals disappear.
  2. removeAll. true releases both $ and jQuery.
  3. Namespace. Call methods through dom.query.
  4. Caution. Many plugins look for window.jQuery — avoid this unless required.

Edge Cases & Pitfalls

Check these before mixing jQuery with another $ library.

order

Load order matters

jQuery can only restore a previous $ if that owner was already on the page when jQuery loaded.

plugins

noConflict(true) breaks many plugins

Plugins often expect window.jQuery. Capture a reference, or avoid removeAll.

two

Two jQuery versions are a last resort

Official docs show it for edge cases. Prefer a single version for size and sanity.

$

Global $ is gone after plain noConflict

Use jQuery, a saved alias, ready’s $, or an IIFE — not bare $ in the global scope.

Browser Support

jQuery.noConflict() has been part of jQuery since 1.0. The optional removeAll flag releases both $ and jQuery from the global scope.

✓ Stable · jQuery 1.0+

jQuery.noConflict()

Works in every browser that runs your loaded jQuery version. Behavior depends on which globals existed before jQuery loaded.

100% Core API
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: Safe for everyday multi-library pages. Prefer plain noConflict() plus jQuery(function($){}) or a saved alias; use true only when necessary.

Performance Notes

ApproachCostBest for
Plain noConflict()NegligibleSharing $ with another lib
Ready / IIFE aliasNegligibleKeeping $ locally for jQuery
Two jQuery buildsExpensive (size)Avoid — one version is enough

noConflict itself is cheap. The real cost is loading extra libraries or duplicate jQuery builds — keep the page to one jQuery when you can.

Key Takeaways

  • Role: give global $ back so another library can use it.
  • Keep jQuery: use jQuery, a saved alias, ready’s $, or an IIFE.
  • Return value: always capture it if you pass true.
  • One build: avoid loading two jQuery versions on one page.

One line: noConflict() frees $ for other libraries — keep calling jQuery via jQuery or a private alias.

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().

Next: jQuery.readyException()

Learn how jQuery reports errors thrown inside ready handlers.

readyException 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.

8 people found this page helpful