-
-
Save diego-betto/d81c94f595334992f24d38223c443f70 to your computer and use it in GitHub Desktop.
Vanilla JavaScript Document Ready
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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