Answer the question
In order to leave comments, you need to log in
How does document.addEventListener work?
I googled this code
actually the code itself the code itself https://codepen.io/graubnla/pen/EgdgZm
inside the pop-up window I have a button that removes an element from the list along with itself, by clicking on it an event like clicked outside the element fires. I solved the problem through setTimeout 500.
It’s actually interesting how it is, because in fact I click on it, and then it is removed, what triggers it like I clicked outside the block?
Answer the question
In order to leave comments, you need to log in
addEventListenter is on the document, not on the element. Therefore, the event fires everywhere.
You need to either hang a listener on the element or check in the event that the click was exactly on the element.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question