V
V
vaskadogana2017-09-07 18:22:26
JavaScript
vaskadogana, 2017-09-07 18:22:26

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

2 answer(s)
I
iRedds, 2017-09-07
@vaskadogana

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.

V
Vahe, 2017-09-08
@vahe_2000

i rewrote your code. is this what you need? https://jsfiddle.net/vaheqelyan/L87txz2p/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question