Skip to content

Instantly share code, notes, and snippets.

@diego-betto
Forked from franzese/DOM-Ready.js
Created September 7, 2017 16:53
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save diego-betto/d81c94f595334992f24d38223c443f70 to your computer and use it in GitHub Desktop.
Save diego-betto/d81c94f595334992f24d38223c443f70 to your computer and use it in GitHub Desktop.
Vanilla JavaScript Document Ready
Document.prototype.ready = function(callback) {
if(callback && typeof callback === 'function') {
document.addEventListener("DOMContentLoaded", function() {
if(document.readyState === "interactive" || document.readyState === "complete") {
return callback();
}
});
}
};
// usage
document.ready(function() { alert('ok!'); });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment