Wait for jQuery to load


/ Published in: JavaScript
Save to your folder(s)

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.


Copy this code and paste it in your HTML
  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();

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.