A Simple Explanation of Event Delegation in JavaScript

Simple, but sometimes not that simple.

See this example and click on important rather than the regular text in the button.

https://jsfiddle.net/8bjs5zdf/

The event.target is the innermost DOM element. If the element can have children you need to use event.target.closest("button") or jQuery’s $(event.target).closest("button") method if you still need IE11 support.

Author: admin

Leave a Reply

Your email address will not be published.