There are events in JavaScript as reference before we start to capture the DOM element: load or DOMContentLoaded or readystatechange , etc. But sometimes, we can't solely depend on either one of those events to detect when the elements have been ready (available) for further DOM manipulation. Especially if the element is injected dynamically . So to answer that, we can use setInterval to wait and repetitively search the particular element(s) we need to find. Using setInterval Let's wrap it with anonymous auto-invoked function . (function (d) { let interval // For keeping "setInterval" method. // Function to check the element. function check() { // The element we need to find. const elementWeNeedToDetect if (elementWeNeedToDetect) { console.log("Element is found"); // Attach a callback or directly do something here. clearInterval(interval) // Stop timer. ...