I have the following code where I search for a dynamic checkbox via it's id value... all mostly works fine, however, I do not want to bog down with a perceptual spin and endless re-checking with my else, how can I limit the below to running the else (re checking the function) to a maximum of 5 times? ... perhaps the question is more of a try catch re catch?
I found a close solution in Java here on SO but not in JavaScript.
After the 5th time of checking a console error should be thrown, I want to check up to 5 times to handle load time inconsistency.
let txt= document.querySelector('input[id^="txt"]');
if (txt) {
console.log("success");
setTimeout(go__, 2000);
} else {
console.log("try again");
setTimeout(currentFunction, 22);
}
Aucun commentaire:
Enregistrer un commentaire