I'm trying to set a delay before every recursive function call. Currently, it's returning undefined. The problem might be the scope of the recursive call (inside settimeout and then).
I tried it like this:
function delay(ms) {
return new Promise(resolve => {
setTimeout(resolve, ms)
});
}
const checkIfListElementIsRendered = (className) => {
delay(10).then(function (res) {
if (document.getElementsByClassName(className)[0]) {
return true;
}
return checkIfListElementIsRendered(className);
})
}
And this:
const checkIfListElementIsRendered = (className) => {
if (document.getElementsByClassName(className)[0]) {
return true;
}
setTimeout(() => {
return checkIfListElementIsRendered(className);
}, 10);
}
Any help is appreciated!