Craig Ward
Craig Ward

Reputation: 2485

Is it possible to run two javascript libraries, MooTools for Selectervizr, jQuery for everything else?

Selectervizr works best with MooTools but the site I am building uses jQuery. How can I make Selectervizr work at its best without just moving completely over to MooTools?

Upvotes: 1

Views: 90

Answers (5)

Maximilian Hils
Maximilian Hils

Reputation: 6770

Both jQuery and mootools have a noConflict (See this and this) mode. You can wrap your code in a function if you want to keep the dollar sign:

(function($){
    //your mootools code
})(document.id);

(function($){
    //your jQuery code
})(jQuery);

Upvotes: 0

Sahil Muthoo
Sahil Muthoo

Reputation: 12496

Use .noConflict()

<script type="text/javascript" src="mootools.js"></script>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
  $.noConflict();
  jQuery(document).ready(function($) {
    // Code that uses jQuery's $ can follow here.
  });
  //$ is free for any library to use here
</script>

Upvotes: 0

voigtan
voigtan

Reputation: 9031

Yes you can, but you should have this in mind: both libraries are "quite big".

jquery have setup so release $ to another library: http://docs.jquery.com/Using_jQuery_with_Other_Libraries

I think mootools also has that. but its enough to change the jquery setup with noConflict

Upvotes: 0

cillierscharl
cillierscharl

Reputation: 7117

Yes, you most definitely can.

Mootools and jQuery both offer a kind of non conflict mode which allow you to use both frameworks by freeing up any ties.

jQuery : jQuery No Conflict

MooTools : MooTools $ safe mode

*Just to note: only one of the above is required.

Upvotes: 3

Hanny
Hanny

Reputation: 2159

I believe JQuery has a 'noconflict' mode - perhaps enable that on the scripts where you need to use mootools/JQuery on the same page.

That has done the trick for me a number of times.

http://api.jquery.com/jQuery.noConflict/

Upvotes: 1

Related Questions