I am trying to figure out how to bind an event to dynamically created elements. I need the event to persist on the element even after it is destroyed and regenerated.
The other solutions are a little overcomplicated...
document.addEventListener('click', e => { if (e.target.closest('.element')) { // .element has been clicked } }
There is a polyfill in case you need to support Internet Explorer or old browsers.