Since both Mootools, jQuery (and even Prototype) use the dollar $
, dollar is the problem that needs to be solved and the source of conflict between the two libraries.
mootools uses the $()
to select elements by ID. So the Mootools code $('meuId')
is similar to the jQuery method $('#meuId')
. Mootools has an alternative to select an element by ID, using document.id('meuId');
Different options:
- Order of loading of scripts:
Mootools detects if dollar $
is already being used and does not re-declare the function $()
, so if Mootools is the last to load the problem it should disappear. In this case it should be used document.id()
in Mootools as per $()
;
jQuery has a method to release the dollar and enter mode of nonconflict. In practice it is even possible to use var jQ = jQuery.noConflict();
and from then on call the jQuery by jQ()
instead of $()
or jQuery()
. The most common is to use jQuery()
instead of $()
, as is the case with Wordpress which loads jQuery into no conflict mode.
(function($){/*...*/})(jQuery)
Another option is to change the dollar Scope. Passing the dollar as a parameter of an anonymous function, this solution is practical to package existing code without having to change all the $
for jQuery
. This variant also needs the declaration jQuery.noConflict()
.
I work a lot with Mootools and I know that there is little documentation on this issue in Portuguese, hence the question-answer.
– Sergio
Since the question has little content, the system signals the same for review for this reason. I suggested to apply one or other common error resulting from the said conflict. This way the question has some code and content. On the other hand, it is interesting so that in the future those who come across this problem without knowing that it is a matter of conflict, through the mistakes in the question, will be able to associate and see the answer :)
– Zuul
@Zuul, you’re right. I added an example. Thank you.
– Sergio