[js] about clearing timer, addEventListener event binding in timer

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)
Apr.01,2021

after looking at the code of the subject, I feel that there will be no problem. I don't worry about running it again. There is no problem indeed. Listener is always there!
can you see if your dom node has changed? this dom is no longer that dom.

Menu