Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 683
Valli69 Avatar asked Nov 19 '25 03:11

Valli69


2 Answers

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.

like image 66
Elliot Bonneville Avatar answered Nov 21 '25 19:11

Elliot Bonneville


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

like image 44
Frankie Avatar answered Nov 21 '25 17:11

Frankie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!