Of course, this method is not limited to jQuery detection, and is common to any Javascript variable or function.
After the current webpage loads jQuery, the jQuery() or $() function will be defined, so there are the following two methods to detect whether jQuery has been loaded:
Method 1:
if (jQuery) {
// jQuery has been loaded
} else {
// jQuery not loaded
}
Method 2:
if (typeof jQuery == 'undefined') {
// jQuery is not loaded
} else {
// jQuery is loaded
}
Note:
Above we check whether the jQuery function has been defined. This is a relatively safe and reliable method, because when you load jQuery.js, you may load the prototype again. js or mootools.js, etc., the $() function may be redefined, and it will be inaccurate to detect whether the $() function exists.