Return to Snippet

Revision: 47292
at June 4, 2011 07:04 by studioevoque


Updated Code
var checker = 0;
	
	function jqueryLoaded() {
		clearInterval(checker);
		//alert('jQuery is loaded, sire!');
	}
	
	function checkJquery() {
		if (window.jQuery) {
        		jqueryLoaded();
		} 
	    	if(checker == 0) {
			//alert('Setting up interval');
        		checker = window.setInterval(checkJquery, 100);
	    	}
	}	

	checkJquery();

Revision: 47291
at June 4, 2011 06:32 by studioevoque


Updated Code
function jqueryLoaded() {
    //do stuff
}

function checkJquery() {
    if (window.jQuery && jQuery.ui) {
        jqueryLoaded();
    } else {
        window.setTimeout(checkJquery, 100);
    }
}

checkJquery();

Revision: 47290
at June 4, 2011 06:31 by studioevoque


Initial Code
function jqueryLoaded() {
    //do stuff
}

function checkJquery() {
    if (window.jQuery && jQuery.ui) {
        jqueryLoaded();
    } else {
        window.setTimeout(checkJquery, 100);
    }
}

checkJquery();2g
T

Initial URL
http://stackoverflow.com/questions/2011938/load-jquery-wait

Initial Description
Sometimes, you need to setup functionality before jQuery is loaded (e.g. because of a template). You can use this snippet to schedule the function after jQuery is loaded.

Initial Title
Wait for jQuery to load

Initial Tags
jquery

Initial Language
JavaScript