Skip to content

Instantly share code, notes, and snippets.

@Ivannnnn
Last active January 4, 2020 17:08
Show Gist options
  • Save Ivannnnn/2a296bbaac6f37e0cb6e7a1b64ba90c3 to your computer and use it in GitHub Desktop.
Save Ivannnnn/2a296bbaac6f37e0cb6e7a1b64ba90c3 to your computer and use it in GitHub Desktop.
Observes changes to an element until false is returned from the callback
const observe = (el, cb, options = { childList: true }) => {
const func = mutations => cb(mutations) === false && mo.disconnect()
const mo = new MutationObserver(func)
mo.observe(el, options)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment