Skip to content

Instantly share code, notes, and snippets.

@gsmartagence
Last active December 29, 2019 16:59
Show Gist options
  • Select an option

  • Save gsmartagence/33bf38424b2519a9ffc27941b9fb7774 to your computer and use it in GitHub Desktop.

Select an option

Save gsmartagence/33bf38424b2519a9ffc27941b9fb7774 to your computer and use it in GitHub Desktop.
/**
* onElementReady.js
* @param {string} element - selector string
*/
const onElementReady = element => (
new Promise((resolve) => {
const waitForElement = () => {
const $element = document.querySelector(element)
if ($element) {
resolve($element)
} else {
window.requestAnimationFrame(waitForElement)
}
}
waitForElement()
})
)
export default onElementReady
{
"name": "onElementReady.js",
"version": "0.1.0"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment