In my project I am using jQuery
in client side and mooTools
in admin side.
I would like to be able to write some part of code (google maps functions, etc) which will be common for both of that libraries.
Is it possibl开发者_Python百科e to check if jQuery
or mooTools
libraries are loaded and use proper behaviours ?
$(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 ?
Both are adding global varibles with its names:
MooTools and jQuery
So just check:
if(window.MooTools) or if(window.jQuery)
Simple:
if ($ === window.jQuery) alert('$ bound to jQuery');
if ($() === document.id()) alert('$ bound to MooTools');
Should do the trick.
We use typeof for this
if(typeof jQuery !== 'undefined')
or
if(typeof MooTools !== 'undefined')
精彩评论