Is it possible to use mootools and jQuery both together

后端 未结 2 1344
[愿得一人]
[愿得一人] 2021-01-20 04:07

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?

相关标签:
2条回答
  • 2021-01-20 04:49

    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.

    0 讨论(0)
  • 2021-01-20 04:54

    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

    0 讨论(0)
提交回复
热议问题