Posted By

studioevoque on 06/04/11


Tagged

jquery


Versions (?)

Wait for jQuery to load


 / Published in: JavaScript
 

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

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.

  1. var checker = 0;
  2.  
  3. function jqueryLoaded() {
  4. clearInterval(checker);
  5. //alert('jQuery is loaded, sire!');
  6. }
  7.  
  8. function checkJquery() {
  9. if (window.jQuery) {
  10. jqueryLoaded();
  11. }
  12. if(checker == 0) {
  13. //alert('Setting up interval');
  14. checker = window.setInterval(checkJquery, 100);
  15. }
  16. }
  17.  
  18. checkJquery();

Report this snippet  

You need to login to post a comment.