Using MooTools and jQuery in SSI Web 7

I'm using version 7 of SSI Web and like some of the features of MooTools and have built it into a couple of my surveys. I now see that version 8 of SSI Web uses jQuery rather than MooTools, which is a very cool thing, since I prefer jQuery over MooTools. But, I'm still using version 7 and want to use both MooTools and jQuery. Can you tell me how?
asked Jun 5, 2012 by JKincaid (450 points)
retagged Sep 13, 2012 by Walter Williams

1 Answer

+1 vote
 
Best answer
You've probably realized that both jQuery and MooTools use the $ function to call up their routines. Fortunately, jQuery is actually namespaced so the $ function is free for MooTools to use. In other words, you may substitute the "$" used in the first jQuery call within a script segment with the text "jQuery", and both jQuery and MooTools code should work just fine. That's what I've used in the code below. Or, if you really want to be on the safe side, just replace the $ in all of your jQuery code with the text "jQuery." Finally, the jQuery site recommends that you add the noConflict() function at the top of your first snippet of jQuery code.

<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
  jQuery.noConflict();
  //jquery stuff
  (function ($) {
    $('p').css('color', '#ff0000');
  })(jQuery);
</script>


The first line loads in the latest version of the jquery.js library from the jQuery CDN site. If you're using v8, this line is unnecessary since it has already been included. The rest is a jQuery script that changes the color of everything on the screen that is within a <p> tag to the color red.

For more information about the jQuery noConflict function, please see: http://api.jquery.com/jQuery.noConflict/
answered Jun 5, 2012 by Nathan Bryce Bronze Sawtooth Software, Inc. (3,140 points)
Thanks Nathan. That's just what I was hoping for. I'll give it a shot and let you know if it doesn't work.