2

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?

4 Answers 4

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.

Sign up to request clarification or add additional context in comments.

Comments

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

Comments

1

The simplest:

if( window.jQuery ) { // you code here } 

Comments

0

To check if jQuery is loaded on the page try:

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.