Since both Mootools , jQuery (and even Prototype ) use the dollar $
the dollar is the problem that has to be solved and the source of conflict between the two libraries.
Mootools uses $()
to select elements by ID. So the Mootools% code with% is similar to the% jQuery method with%. Mootools has an alternative to select an element by ID, using $('meuId')
Different options:
Mootools detects whether the $('#meuId')
dollar is already in use and does not re-declare the document.id('meuId');
function, so if Mootools is the last to load the problem should disappear. In this case you should use $
in Mootools instead of $()
;
jQuery has a method to free the dollar and enter non-conflict mode >. In practice it is even possible to use $()
and hence call jQuery by jQuery.noConflict()
instead of var jQ = jQuery.noConflict();
or jQ()
. The most common is to use $()
instead of jQuery()
, as is the case of Wordpress that loads jQuery in non-conflict mode.
Another option is to change the scope of the dollar. Passing the dollar as a parameter for an anonymous function, this solution is practical to package existing code without having to change all $()
to (function($){/*...*/})(jQuery)
. This variant also needs the $
statement.