最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Check if jQuery or mooTools are loaded - Stack Overflow

programmeradmin0浏览0评论

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 possible 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 ?

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 possible 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 ?

Share Improve this question asked Jul 16, 2010 at 9:05 hszhsz 152k62 gold badges266 silver badges320 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 14

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)

  1. 暂无评论