jQuery noConflict() Method

You are Here:

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

ValueTypeExplanation
removeAllOptionalSpecifies a boolean indicating whether to remove all jQuery variables from the global scope (including jQuery itself).

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>

Reminder

Hi Developers, we almost covered 99.5% of jQuery Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in jQuery.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author