In addition to using setInterval, you can also use the recursive setTimeout template, for example:
(function doCheck(){ setTimeout(function(){ if ($(.element).length ) {
While this does not seem likely in your case, see times when using setInterval is considered harmful. From the documentation :
If it is likely that your logic may take longer to execute than a time interval, it is recommended that you call recursively using the window.setTimeout function. For example, when using setInterval to poll a remote server every 5 seconds, network delays, an unresponsive server, and many other problems may request completion at the appointed time. This way, you can find yourself with XHR requests in the queue, which do not necessarily return in order.
For such cases, the recursive setTimeout pattern is preferred.
source share