I have a div that is created by a plugin and appears after the page is rendered (always at different times).
I need to check if this div exists, then execute a set of functions. However if it does not exist yet, I want to wait(check) until it appears, then execute that set of functions.
Here is what I'm using right now:
var check = setInterval(function(){
if ($('#target-div').length){
console.log('execute set of functions')
clearInterval(check);
}
}, 100);
However, is there a way to permanently check if the div exits (like running it in the background or something) and as soon as it gets created - stop, but without setInterval?
Because I have multiple similar checks and it gets a total mess having to set a new/different setInterval each time.
Thanks.