JSFiddle - React, Tailwind, and code Playground
by Sahin Deniz
JavaScript 1.7
function WaitForElement(query, atLeast=1){
return new Promise(function(resolve, reject) {
console.log(arguments);
let elements,
_loop_expireTime = Date.now()+(30*1000);
let _loop = setInterval(() => {
if (_loop_expireTime < Date.now()) {
clearInterval(_loop);
console.error("Can't find anything with", query);
reject();
return false;
}
elements = document.querySelectorAll(query);
if (elements.length >= atLeast) {
clearInterval(_loop);
resolve(elements);
}
});
});
}
async function init(){
console.log(1);
let element = await WaitForElement(".deneme");
console.log(element);
console.log(2);
}
init();
setTimeout(()=>{
$(`<div class="deneme">test</div>`).appendTo("body");
},3000)