Check if jQuery or mooTools are loaded

In my project, I use jQueryclient side and mooToolsadmin side. I would like to be able to write some of the code (google maps functions, etc.) that will be common for both of these libraries.

Is it possible to check if libraries are loaded jQueryor mooTools, and use the correct behavior?

$(document).ready(function() {}); or window.addEvent('domready', function(){});

$('#id'); or $('id');

$('googleMapLocalize').addEvent('click', function(){}); or $('googleMapLocalize').bind('click', function(){});

What is the best way?

+5
source share
3 answers

Both add global variables with names:

MooTools and jQuery

So just check:

if(window.MooTools) or if(window.jQuery)
+14
source

Plain:

if ($ === window.jQuery) alert('$ bound to jQuery');

if ($() === document.id()) alert('$ bound to MooTools');

Gotta do the trick.

+7
source

typeof

if(typeof jQuery !== 'undefined')

if(typeof MooTools !== 'undefined')
0

All Articles