jQuery.noConflict() Method

Last Updated:

jQuery noConflict() Method

Like jQuery, there are many JavaScript libraries use $ as a shortcut instead of the full name, just as jQuery does.

In jQuery's case, $ is just an alias for jQuery, so all functionality is available without using $.

To use jQuery functionality without using $ sign. You just have to following any of the following method

  • In simple way, just replace $ sign with jQuery.
  • Use $.noConflict() method to create your own shortcut.

Replace $ with jQuery

In the following example, we will using jQuery instead of $ sign.

Example

HTML Editor
<!DOCTYPE html> <html lang="en-US"> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> </head> <body> <h1>jQuery noConflict() Method</h1> <button>Click</button> <script> jQuery(document).ready(function(){ jQuery("button").click(function(){ alert("jQuery executed"); }); }); //Do something with another library's $(). </script> </body> </html>

Syntax

$.noConflict(removeAll);

Parameter Values

Value Type Explanation
removeAll Optional Specifies a boolean indicating whether to remove all jQuery variables from the global scope (including jQuery itself).

Browser Support

Devicedesktopmobile
Browsergoogle chromesafarifirefoxinternet Exploreredgeoperagoogle chromesafarifirefoxedgeoperaandroid webviewsamsung internet
$.noConflict()YesYesYesYesYesYesYesYesYesYesYesYesYes

Use $.noConflict() method

In the following example, we will using jq instead of $ sign.

Example

HTML Editor
<!DOCTYPE html> <html lang="en-US"> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> </head> <body> <h1>jQuery noConflict() Method</h1> <button>Click</button> <script> var jq = $.noConflict(); jq(document).ready(function(){ jq("button").click(function(){ alert("jQuery executed"); }); }); //Do something with another library's $(). </script> </body> </html>

Share this Page

Meet the Author