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.
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn