jQuery – The noConflict() Method
What if you wish to use other frameworks on your pages, while still using jQuery?
As you already know; jQuery uses the $ sign as a shortcut for jQuery.
Some of the other frameworks also use the $ character as a shortcut (just like jQuery), and then you suddenly have two different frameworks using the same shortcut, which might result in that your scripts stop working.
The jQuery team have already thought about this, and implemented the noConflict() method.
The jQuery noConflict() Method
The noConflict() method releases the hold on the $ shortcut identifier, so that other scripts can use it.
You can of course still use jQuery, simply by writing the full name instead of the shortcut:
jQuery(“p”).text(“jQuery is still working!”);
<p>This is a paragraph.</p>
You can also create your own shortcut very easily. The noConflict() method returns a reference to jQuery, that you can save in a variable, for later use. Here is an example:
jq(“p”).text(“jQuery is still working!”);
If you have a block of jQuery code which uses the $ shortcut and you do not want to change it all, you can pass the $ sign in as a parameter to the ready method. This allows you to access jQuery using $, inside this function – outside of it, you will have to use “jQuery”:
$(“p”).text(“jQuery is still working!”);