Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@vaporwavie
Last active May 6, 2020 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vaporwavie/57d17421961f4c98ba085ef054729f9a to your computer and use it in GitHub Desktop.
Save vaporwavie/57d17421961f4c98ba085ef054729f9a to your computer and use it in GitHub Desktop.
Document is literally ready
const DOMisReady = (handler: () => void) => {
if (document.readyState !== "loading") {
handler();
} else {
document.addEventListener("DOMContentLoaded", handler);
}
}
// Usage
DOMisReady(() => {
// do your magic
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment