Created
July 18, 2021 18:33
-
-
Save lucaslgr/4d9248898e09912055f3eb7b7df871df to your computer and use it in GitHub Desktop.
Pega elemento na tela async
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
//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