[Javascript] event delegation order
Anthony Ettinger
anthony at chovy.com
Wed May 2 14:57:26 CDT 2007
I'm reading through PPK's article at:
http://www.quirksmode.org/js/events_order.html
Near the bottom, there is an explanation of currentTarget with 2 event
handlers registered...I'm confused here how and why clicking on
element2 would trigger the event handler twice.
Here is an excerpt:
------------------------------------
| document |
| --------------- ------------ |
| | element1 | | element2 | |
| --------------- ------------ |
| |
------------------------------------
element1.onclick = doSomething;
element2.onclick = doSomething;
document.onclick = defaultFunction;
.....
But suppose we register these event handlers:
element1.onclick = doSomething;
element2.onclick = doSomething;
If the user clicks on element2 doSomething() is executed twice.
========
WHY is doSomething() called twice from element2 if element1 is a
sibling (not an ancestor/child)?
--
Anthony Ettinger
Ph: 408-656-2473
http://chovy.dyndns.org/resume.html
http://utuxia.com/consulting
More information about the Javascript
mailing list