Skip to content

Instantly share code, notes, and snippets.

@lucaslgr
Created July 18, 2021 18:33
Show Gist options
  • Save lucaslgr/4d9248898e09912055f3eb7b7df871df to your computer and use it in GitHub Desktop.
Save lucaslgr/4d9248898e09912055f3eb7b7df871df to your computer and use it in GitHub Desktop.
Pega elemento na tela async
//Funcao que pega um elemento na tela de forma assincrona
function getElementAsync(selector) {
return new Promise((resolve, reject) => {
const element = null;
const idInterval = setInterval(() => {
try {
const element = document.querySelector(selector);
if (element) {
clearInterval(idInterval);
resolve(element);
}
} catch (error) {
console.log(error);
}
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment