Skip to content

Instantly share code, notes, and snippets.

@devfred
Last active October 5, 2015 00:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devfred/2726369 to your computer and use it in GitHub Desktop.
Save devfred/2726369 to your computer and use it in GitHub Desktop.
javascript: jQuery dom ready before jquery is loaded
/* This snippet allowes function to user jQuery dom ready before jquery is loaded */
window.$ = (function() {
var q = [], f = function (cb) {
q.push(cb);
};
f.attachReady = function ($) {
$(function () {
$.each(q, function(i, f) {
f();
});
q.length = 0; // clear it, just in case
});
return $;
}
return f;
})();
/*
Use the following to call the functions
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script type="text/javascript">
$.noConflict();
$ = $.attachReady(jQuery);
</script>
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment