Event Handling versus Event Delegation
By Christian Heilmann | September 24th, 2006 | Filed in Action, DOM, DOM Scripting TF, General, Training
Skip to comment formIt is not new, but it still is rather clever: In order to avoid having to add event handlers to each and every element you want to monitor, you can use one single handler on a parent element and let browser event bubbling do the rest of the work for you.
Check out this quick example of event handling versus event delegation to see how it is done and what the benefits are.
Your Replies
- #1 On September 25th, 2006 12:44 pm Greg Reimer replied:
-
It would be nice to see some non-Yahoo example code. Interesting though.
- #2 On October 2nd, 2006 7:14 am lisongfeng replied:
-
Heilmann’s idea is greate!
- #3 On October 8th, 2006 5:35 am Marc van den Dobbelsteen replied:
-
This mechanism can be used (i did) to create a event-broadcasting mechanism like we know in the oo-world. This is a very handy model when developing RIA’s (Rich Internet Applications) . You can create loosely coupled interface objects. For example multiple output objects like a graph or gauge, reacting on the value set on a input element like a slider or textbox.