Loading Please Wait...

Logo Lynxsia IT Solutions

jQuery noConflict

JQ noConflict

What if you wish to use other frameworks on your pages, while still using jQuery?

jQuery and Other JavaScript Frameworks

As you already know; jQuery uses the $ sign as a shortcut for jQuery.

There are many other popular JavaScript frameworks like: Angular, Backbone, Ember, Knockout, and more.

What if other JavaScript frameworks also use the $ sign as a shortcut?

If two different frameworks are using the same shortcut, one of them might stop working.

The jQuery team have already thought about this, and implemented the noConflict() method.

The jQuery noConflict() Method

The jQuery 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:

					 
        
          $.noConflict();
          jQuery(document).ready(function(){
            jQuery("button").click(function(){
              jQuery("p").text("jQuery is still working!");
            });
          });
        
      

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:

					 
        
          var jq = $.noConflict();
          jq(document).ready(function(){
            jq("button").click(function(){
              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":

					 
        
          $.noConflict();
          jQuery(document).ready(function($){
            $("button").click(function(){
              $("p").text("jQuery is still working!");
            });
          });
        
      

How you feel about this blog:

Share this blog on:

Report Us

If you find any error in the turtorials, or want to share your suggestion/feedback, feel free to send us email at: info@lynxsia.com

Contact Us
Ads
Logo
Lynxsia IT Solutions

We are concern with various development process like website design & development, E-commerce development, Software development, Application development, SMS & Bulk SMS Provider, PWA Development, and many more..

Kotwali Road, Chhiptehri, Banda, 210001, UP, India

Copyright © 2022, Lynxsia IT Solutions, All rights reserved