Skip to content

Instantly share code, notes, and snippets.

@lebbe
Created August 8, 2014 12:09
Show Gist options
  • Save lebbe/14055d176e76c6788ffb to your computer and use it in GitHub Desktop.
Save lebbe/14055d176e76c6788ffb to your computer and use it in GitHub Desktop.
A little snippet to make sure that jQuery is loaded before running code.
(function($, callback) {
if($) {
callback();
return;
}
var script = document.createElement('script');
script.src = '//code.jquery.com/jquery-1.11.1.min.js';
script.onload = callback;
document.getElementsByTagName('body')[0].appendChild(script);
})(window['jQuery'], function() {
var $ = jQuery;
/** jQuery dependent code here. **/
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment