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 badges4 Answers
Reset to default 7if (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条)