jQuery.noConflict()

Many JavaScript libraries use $ as a function or variable name, just as jQuery does. In jQuery’s case, $ is just an alias for jQuery, so all functionality is available without using $. If we need to use another JavaScript library alongside jQuery, we can return control of $ back to the other library with a call to $.noConflict()

Example :

<script type="text/javascript">
  $.noConflict();
  jQuery(document).ready(function($) {
    // Code that uses jQuery's $ can follow here.
  });
  // Code that uses other library's $ can follow here.
</script>
See more - http://api.jquery.com/jQuery.noConflict/

You May Also Like

Never Miss Any Web Tutorials, Guides, Tips and Free eBooks

Join Our Community Of 50,000+ Web Lovers and get a weekly newsletter in your inbox

 

I hate spam too. Unsubscribe at any time.

5 thoughts on “jQuery.noConflict()”

    • you can use both together! Since MooTools is prototype-based and jQuery is not, jQuery and MooTools may be used together on the same page.

      //no conflict jquery
      jQuery.noConflict();
      //jquery stuff
      (function($) {
      $(‘p’).css(‘color’,’#ff0000′);
      })(jQuery);

      //moo stuff
      window.addEvent(‘domready’,function() {
      $$(‘p’).setStyle(‘border’,’1px solid #fc0′);
      });

      jQuery is namespaced so the $ function is free for MooTools to take hold of. The jQuery code passes jQuery to itself and then we call the argument $, thus jQuery is contained, so to speak.

      Obviously including two libraries within the same page is resource-consuming but if it’s acceptable to the project and allows you to implement plugins from each library quickly, this may be a great option for you.

      hope this helps.. 🙂

      Reply
    • you can use both together! Since MooTools is prototype-based and jQuery is not, jQuery and MooTools may be used together on the same page.

      //no conflict jquery
      jQuery.noConflict();
      //jquery stuff
      (function($) {
      $(‘p’).css(‘color’,’#ff0000′);
      })(jQuery);

      //moo stuff
      window.addEvent(‘domready’,function() {
      $$(‘p’).setStyle(‘border’,’1px solid #fc0′);
      });

      jQuery is namespaced so the $ function is free for MooTools to take hold of. The jQuery code passes jQuery to itself and then we call the argument $, thus jQuery is contained, so to speak.

      Obviously including two libraries within the same page is resource-consuming but if it’s acceptable to the project and allows you to implement plugins from each library quickly, this may be a great option for you.

      hope this helps.. 🙂

      Reply

Leave a Comment