Valli69
Valli69

Reputation: 9902

Is it possible to use mootools and jQuery both together

I have to use mootools and jquery files together. But there is a conflict occurs while using both together. Is there any solution to avoid this conflict?

Upvotes: 3

Views: 3275

Answers (2)

Elliot Bonneville
Elliot Bonneville

Reputation: 53311

Yes, you'll have to include this code just after you include your jQuery and before you include Mootools.

<script>
    var j$ = jQuery.noConflict();
</script>

You'll then want to find/replace all jQuery $ references with j$, preferably using the automated tool found in most code editors.


You also have another option, a closure. It would look something like this, if I remember correctly:

(function($) {
  //jQuery stuff
})(jQuery);

You'll want to move all your existing code inside this function. It scopes the $ variable so you can do business with jQuery as usual within the closure, then use Mootools outside of it.

Upvotes: 6

Frankie
Frankie

Reputation: 25165

It is (possible to use both libraries together).

From the official jQuery site on how to make it work with other libraries: http://docs.jquery.com/Using_jQuery_with_Other_Libraries

Upvotes: 2

Related Questions