How to detect if the jquery library is loaded

Source: Internet
Author: User
Tags min jquery library

To detect if the jquery library is already loaded, you can use the following JavaScript code:

if (typeof JQuery! = ' undefined ') {
Alert ("JQuery library is loaded!");
}Else{
Alert ("JQuery Library is not found!");
}

Another option.

In some blogs and forums it is mentioned that you can use code to achieve the same purpose.

If
Alert ("JQuery library is loaded!");
}Else{
Alert ("JQuery Library is not found!");
}

However, this would not work, and when the jquery library was not loaded, the above code would fail (jquery was not defined as jqueryis not define), and the warning message would not be executed.

Finally, a jquery detection code is often recommended.

<title>jquery Library is loaded or not</title>
<body>
<script type= "Text/javascript" src= ". /jquery-1.11.1.min.js "></script>
<script type= "Text/javascript" >
if (typeof jquery!= ' undefined ') {
Alert ("JQuery library is loaded!");
} else{
Alert ("JQuery library is not found");

}

if (jQuery) {

Alert ("JQuery library is loaded!");

}else{

Alert ("JQuery Library is not found!");

}
</script>
</body>

1 The effect diagram of the jquery is loaded:




After clicking OK:


<title>jquery Library is loaded or not</title>
<body>
<script type= "Text/javascript" src= ". /jquery-1.11.108.min.js "></script>
<script type= "Text/javascript" >
if (typeof jquery!= ' undefined ') {
Alert ("JQuery library is loaded!");
} else{
Alert ("JQuery library is not found");

}

if (jQuery) {

Alert ("JQuery library is loaded!");

}else{

Alert ("JQuery Library is not found!");

}
</script>
</body>

The effect of changing the name of the jquery library to a nonexistent name:


After clicking OK:



Summarize:

As you can see, the first method is correct and the second method is flawed.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.