let checkExist = setInterval(function() { if ($('#the-canvas').length) { console.log("Exists!"); clearInterval(checkExist); // if it appeared, stop the loop } }, 100); // check every 100ms