Skip to content

Instantly share code, notes, and snippets.

@westc
Created December 23, 2023 01:57
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 westc/4b29520bbfb30a9a589a8df618395412 to your computer and use it in GitHub Desktop.
Save westc/4b29520bbfb30a9a589a8df618395412 to your computer and use it in GitHub Desktop.
Function that waits for the DOM to be ready to be manipulated.
/**
* Function that waits for the DOM to be ready to be manipulated.
* @returns {Promise<undefined>}
* A promise that will be finished after the DOM is ready to be manipulated.
*/
function waitForReadyDOM() {
return new Promise(async resolve => {
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', () => resolve());
else resolve();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment