Home  >  Article  >  Web Front-end  >  Determination code to detect whether jQuery.js has been loaded_jquery

Determination code to detect whether jQuery.js has been loaded_jquery

WBOY
WBOYOriginal
2016-05-16 18:06:331131browse

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:

Copy code The code is as follows:

if (jQuery) {
// jQuery has been loaded
} else {
// jQuery not loaded
}


Method 2:
Copy code The code is as follows:

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