Quick Tip: Resolving conflicting problems between jQuery and MooTools or any other Javascript library

Recently I wrote quite a huge chunk of jQuery for a website and it worked fine. A few days later I checked back to make sure that everything was working correctly after modifying a few things, but to my surprise none of the jQuery code worked. The problem was that I had added some Mootools code, the Mootools code worked fine but the jQuery code did not. I done some searching and found that the two libraries were conflicting and all it takes is 2 extra lines of code to prevent this from happening.

If you was to include jQuery and Mootools together this code below would not work:

$(document).ready(function(){
    alert("Hello World!");
});

But if we simply add jQuery(function($){ and }); then this code would work the way that we have intended.

The code would look like this:

jQuery(function($){
    $(document).ready(function(){
        alert("Hello World!");
    });
});

More information

I hope you found this quick tip useful, you can find out more about jQuery conflicts here.

Feel free to leave a comment with your thoughts.

Bookmark and Share
Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • email
  • FriendFeed
  • LinkedIn
  • Ping.fm
  • Tumblr
  • Twitter

No related posts.

Related posts brought to you by Yet Another Related Posts Plugin.

, , , , ,

No comments yet.

Leave a Reply