on-internet
← Community

Why does clicking the icon inside a dynamically added button not trigger my delegated click handler, while clicking the button text does?

Stack Overflow ·

I am building a small task list where items are added with JavaScript. Instead of adding a click listener to every button, I added one listener to the list itself. Each item has a delete button with a small icon inside it. When I click the text part of the delete button, the item is removed as expected. When I click directly on the icon inside the same button, nothing happens. There is no error in the console, and the item stays on the page. Here is a simplified version of what I have: <ul id="taskList"> <li>Buy milk <button data-action="delete">Delete <svg viewBox="0 0 10 10"><path d="M1 1 L9

Comments

Sign in or sign up to comment and upvote.

No comments yet.