Skip to content

Instantly share code, notes, and snippets.

@habibimroncn
Created October 27, 2022 13:36
Show Gist options
  • Save habibimroncn/f82aa8faeb535e4bad5308457044143a to your computer and use it in GitHub Desktop.
Save habibimroncn/f82aa8faeb535e4bad5308457044143a to your computer and use it in GitHub Desktop.
Waiting element exists
function avocaWaitForElm(selector) {
return new Promise(resolve => {
if (document.querySelector(selector)) {
return resolve(document.querySelector(selector));
}
const observer = new MutationObserver(mutations => {
if (document.querySelector(selector)) {
resolve(document.querySelector(selector));
observer.disconnect();
}
});
observer.observe(document.body, {
childList: true,
subtree: true
});
});
}
avocaWaitForElm('input[name="mf-date-cs').then((elm) => {
console.log('Element is ready');
console.log(elm.textContent);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment