Created
December 23, 2023 01:57
-
-
Save westc/4b29520bbfb30a9a589a8df618395412 to your computer and use it in GitHub Desktop.
Function that waits for the DOM to be ready to be manipulated.
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 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