Last active
October 16, 2017 19:53
-
-
Save olemak/fcca287e88762176c9085160d201f1b1 to your computer and use it in GitHub Desktop.
`JavaScript (ES2015) native "on 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
(() => { function fn() { | |
// "On document ready" commands: | |
console.log(document.readyState); | |
}; | |
if (document.readyState != 'loading') {fn()} | |
else {document.addEventListener('DOMContentLoaded', fn)} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No need to include jQuery just to check if the DOM is interactive with $().ready - this little snippet will do the same with native JavaScript (will have to be transpiled for non-2015 compliant browsers... but you were doing that anyway, right?