Hmm, I imagine that all you have to do is add a check in the if
line that determines whether the object is defined or not.
That would look something like this:
function myFunction() {
let someComponentClass = document.getElementsByClassName("...");
if(someComponentClass && someComponentClass.length > 0) {
clearInterval(refreshID);
}
}
// call this function every 250 ms
let refreshID = setInterval(myFunction, 250);
I referenced this stackoverflow post btw
Let me know if this helps.