javascript - How to check whether the jQuery file is loaded on the page or not? - Stack Overflow

How do I check whether jQuery is loaded in the page or not? I have to run a jQuery script which has a j

How do I check whether jQuery is loaded in the page or not? I have to run a jQuery script which has a jQuery library link, but when I use the code I want to make sure to load that file only if the page does not have any jQuery file, otherwise use that file. Any suggestions?

How do I check whether jQuery is loaded in the page or not? I have to run a jQuery script which has a jQuery library link, but when I use the code I want to make sure to load that file only if the page does not have any jQuery file, otherwise use that file. Any suggestions?

Share Improve this question edited Dec 21, 2011 at 19:32 Adam 45k17 gold badges107 silver badges145 bronze badges asked Dec 21, 2011 at 19:27 disckydiscky 15.3k8 gold badges22 silver badges11 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 7
if (typeof jQuery == 'undefined') {
   // This means jQuery is not loaded
}

Also, take a look at yepnope.js, it allows you to load different JavaScript files based on if certain conditions are true or false.

if (typeof jQuery != 'undefined') {
 // jQuery is loaded
}

The simplest:

if( window.jQuery ) { 

 // you code here 
} 

To check if jQuery is loaded on the page try:

if (!(window.jQuery || window.$)){
 //then load it
} else {
//already loaded
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744759698a4592099.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信