[Javascript] event delegation order
Nick Fitzsimons
nick at nickfitz.co.uk
Wed May 2 15:24:44 CDT 2007
On 2 May 2007, at 20:57:26, Anthony Ettinger wrote:
> http://www.quirksmode.org/js/events_order.html
>
>
<snip>
>> ------------------------------------
>> | document |
>> | --------------- ------------ |
>> | | element1 | | element2 | |
>> | --------------- ------------ |
>> | |
>> ------------------------------------
>>
>> element1.onclick = doSomething;
>> element2.onclick = doSomething;
>> document.onclick = defaultFunction;
<snip>
>> 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)?
It is rather unclear, but I believe at that point he's gone back to
referring to the original diagram, where element1 was a child of
element2. Seen in that context, it should make sense. It's possible
the two parts got separated when the article was edited.
You might want to contact ppk (there's a "Contact" link at the bottom
of the page) to point out that the article is unclear at that point -
he's very committed to providing accurate information, and I'm sure
he would welcome the opportunity to clarify the article.
Regards,
Nick.
--
Nick Fitzsimons
http://www.nickfitz.co.uk/
More information about the Javascript
mailing list