I wrote a timer to detect whether an element appears on the dom tree. If I detected it, I bound an event to the element, using addEventListener, and then I cleared the timer. However, the event bound to this element also failed. Is it because clearing the timer caused the called function to be destroyed in memory? If I insist on destroying the timer, is there any other way to ensure that the element listens for events properly?
var timer = setInterval(() => {
let dom = document.getElementsByClassName("ke-upload-file")[0]
if (dom) {
dom.addEventListener("change", function (e) {
console.log("")
})
clearInterval(timer)
}
}, 1000)