Skip to content

Instantly share code, notes, and snippets.

@bartwttewaall
Created February 4, 2021 17:10
Show Gist options
  • Save bartwttewaall/db3dc9ca05ec30b3ed3c425deba69477 to your computer and use it in GitHub Desktop.
Save bartwttewaall/db3dc9ca05ec30b3ed3c425deba69477 to your computer and use it in GitHub Desktop.
function domReady(callback) {
if (['interactive', 'complete'].includes(document.readyState)) {
callback();
} else {
document.addEventListener('DOMContentLoaded', callback);
}
}
domReady(() => {
if (!document.body) return;
console.log('dom is ready, init something...');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment