Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect what Library is behind the $ function?

I am developing some JavaScript that should work with either Prototype.js or JQuery, thus I need some way to identify what is the primary library in use. How can I do that?

like image 781
clops Avatar asked May 02 '10 20:05

clops


2 Answers

You can check for jQuery like this:

if (window.$ === window.jQuery)
like image 197
SLaks Avatar answered Sep 23 '22 16:09

SLaks


Well, you could check for the presence of jQuery:

if(window.jQuery !== "undefined")
{
    // jQuery Yay!
}

and then if it is assigned to $

if(window.jQuery === window.$)
{
    // jQuery Yay!
}
like image 26
Tyler Carter Avatar answered Sep 23 '22 16:09

Tyler Carter