开发者

Check if jQuery or mooTools are loaded

开发者 https://www.devze.com 2023-01-08 02:23 出处:网络
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 librari

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')
0

精彩评论

暂无评论...
验证码 换一张
取 消