Created
June 29, 2016 01:30
-
-
Save franzese/9e7c1ab6d3c2a11474a73f5eb0d3d153 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
Tested in Chrome 50+ and Firefox 45+