© 2026 LinearBytes Inc.
Search posts, tags, users, and pages
Sandeep Panda
co-founder, Hashnode
You should look at event delegation. In your case, you can bind events to the non-dynamic parent so that the event handlers aren't unbound when new child elements are added or some are replaced.
John Enderby
Opportunity is everywhere
I was actually looking into this. Would I then use if statements, or switches, to define functionality based on what was clicked/interacted with?
Pankaj Patel
Blog, Tech, Photography etc.
yes, in case of event delegation there will be few checks to examine of correct element is clicked to do related operations.
Edouard Duplessis
Fullstack PHP JS
example event delegation: https://davidwalsh.name/event-delegate
Thanks Edouard, I had read this but didn't know if this was the right approach. I have actually come up with another solution just now!