Conflict between Mootools and jQuery causes script(s) to stop working

AID: 3099
  • Status: Published

1830 points

  • Bystone5150
  • TypeTips/Tricks
  • Posted on2010-05-16 at 08:00:20
Both jQuery and Mootools offer some nice, easy to use scripts. Mootools is best known for their interactive slideshows and jQuery for their menus, but both have many other uses as well.  

jQuery is basically a toolkit with many DOM-related features while Mootools is more modular. They conflict because they have a few identically named functions and namespaces and as a result one or both scripts don't work, or at least don't work properly. In my experience it usually it is Mootools that loses out in this deal.

There are several workarounds available to make jQuery and Mootools work together. Some call for editing the core scripting of jQuery and others call for modifying your script, mostly just to avoid conflict with the "$" function that both rely on heavily. I tried several of these in the past, none worked that well and most just plain broke the script entirely. Maybe it was my fault for not implementing the changes properly, I dunno. I would post those here but it may confuse some who, like me, sometimes just skim pages looking for code snippets to fix what they already have.

After trying the hard way numerous times I found a very simple addition to jQuery scripts that makes it free up constants and variables so that other modules, like Mootools, can use them. In the simplest of terms you tell jQuery to not conflict.

Just add the following little line to the very top of your Jquery script(s), right after the script tag.
<script type="text/javascript" language="javascript">
jQuery.noConflict();

// your script here

</script>
                                    
1:
2:
3:
4:
5:
6:

Select allOpen in new window



This method will usually make Jquery and Mootools play nice together with the least amount of headache. It has worked for me many times.
Asked On
2010-05-16 at 08:00:20ID3099
Tags

jquery

,

mootools

,

conflict

,

javascript

,

DOM

,

module

,

not working

,

script broken

Topic

JavaScript

Views
1279

Comments

Add your Comment

Please Sign up or Log in to comment on this article.

Join Experts Exchange Today

Gain Access to all our Tech Resources

Get personalized answers

Ask unlimited questions

Access Proven Solutions

Search 3.2 million solutions

Read In-Depth How-To Guides

1000+ articles, demos, & tips

Watch Step by Step Tutorials

Learn direct from top tech pros

And Much More!

Your complete tech resource

See Plans and Pricing

30-day free trial. Register in 60 seconds.

Loading Advertisement...

Top JavaScript Experts

  1. leakim971

    511,289

    Sage

    2,168 points yesterday

    Profile
    Rank: Genius
  2. mplungjan

    291,279

    Guru

    2,800 points yesterday

    Profile
    Rank: Savant
  3. nap0leon

    195,491

    Guru

    0 points yesterday

    Profile
    Rank: Sage
  4. Proculopsis

    182,948

    Guru

    0 points yesterday

    Profile
    Rank: Sage
  5. COBOLdinosaur

    157,309

    Guru

    0 points yesterday

    Profile
    Rank: Genius
  6. chaituu

    130,684

    Master

    0 points yesterday

    Profile
    Rank: Sage
  7. Ray_Paseur

    130,217

    Master

    330 points yesterday

    Profile
    Rank: Savant
  8. tommyBoy

    125,345

    Master

    0 points yesterday

    Profile
    Rank: Genius
  9. StingRaY

    114,318

    Master

    0 points yesterday

    Profile
    Rank: Wizard
  10. DaveBaldwin

    80,081

    Master

    336 points yesterday

    Profile
    Rank: Genius
  11. ansudhindra

    79,054

    Master

    2,000 points yesterday

    Profile
    Rank: Wizard
  12. ChrisStanyon

    62,768

    Master

    800 points yesterday

    Profile
    Rank: Sage
  13. hielo

    61,266

    Master

    0 points yesterday

    Profile
    Rank: Savant
  14. HainKurt

    59,030

    Master

    0 points yesterday

    Profile
    Rank: Genius
  15. BuggyCoder

    54,739

    Master

    0 points yesterday

    Profile
    Rank: Sage
  16. mroonal

    54,339

    Master

    10 points yesterday

    Profile
    Rank: Sage
  17. tagit

    54,093

    Master

    1,600 points yesterday

    Profile
    Rank: Genius
  18. gurvinder372

    52,824

    Master

    10 points yesterday

    Profile
    Rank: Genius
  19. basicinstinct

    52,586

    Master

    0 points yesterday

    Profile
    Rank: Genius
  20. JonNorman

    45,158

    2,200 points yesterday

    Profile
    Rank: Master
  21. Lalit-Chandra

    44,420

    0 points yesterday

    Profile
    Rank: Master
  22. xmediaman

    36,450

    3,800 points yesterday

    Profile
    Rank: Guru
  23. kozaiwaniec

    33,100

    0 points yesterday

    Profile
    Rank: Guru
  24. Kravimir

    32,700

    0 points yesterday

    Profile
    Rank: Genius
  25. designatedinitializer

    32,300

    0 points yesterday

    Profile
    Rank: Master

Hall Of Fame