Skip to content

Instantly share code, notes, and snippets.

@olemak
Last active October 16, 2017 19:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save olemak/fcca287e88762176c9085160d201f1b1 to your computer and use it in GitHub Desktop.
Save olemak/fcca287e88762176c9085160d201f1b1 to your computer and use it in GitHub Desktop.
`JavaScript (ES2015) native "on document ready"
(() => { function fn() {
// "On document ready" commands:
console.log(document.readyState);
};
if (document.readyState != 'loading') {fn()}
else {document.addEventListener('DOMContentLoaded', fn)}
})();
@olemak
Copy link
Author

olemak commented Jul 6, 2016

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment