Does removing elements from the DOM on their event handlers eliminate?

If I remove an element from the DOM with attached event handlers and subsequently add an element with the same identifier somewhere, will the new element have handlers?

+4
source share
3 answers

No, because it will be a different object. If you used jQuery and live() , you will get this behavior.

+6
source

No, but you can see the delegation of events. The basic idea is that events will bubble up to the parent DOM elements so you can attach your event handler above the DOM. You can register for an event, such as a click, and provide the rules for this handler to what it should do with the click events of the children. This handler will continue to be present when its children are added or removed, so there is no need to register event handlers on the individual elements themselves. Here's a link

+2
source

no, the new item will not be attached by the handler, you will have to reassign the handlerโ€™s exploit

0
source

Source: https://habr.com/ru/post/1302873/


All Articles