W3C home > Mailing lists > Public > whatwg@whatwg.org > March 2007

[whatwg] Adding mouseenter and mouseleave events

From: Gareth Hay <gazhay@gmail.com>
Date: Thu, 15 Mar 2007 19:10:33 +0000
Message-ID: <677B8BFC-96D5-4DCD-A987-688316603812@gmail.com>
I'm not so sure it is a workaround though.
If you know that the event will bubble, you can make your handler  
prevent bubbling.

I don't think we should be adding two new events to a spec, when the  
existing events can work in the way you want, albeit with a line more  
code. If we did, we'd be forever adding very specialized events.


>>> Mouseover/out events will trigger when elements contained inside  
>>> the EventTarget are hovered, and then bubble up. This is contrary  
>>> to the most obvious interpretation, as you are still inside  
>>> (over) the targeted element. IE supports two events, mouseenter 
>>> [1] and mouseleave[2], which solve this problem by not bubbling.
>>>
>>> It is possible to work around the problem by using target/ 
>>> relatedTarget and walking up the DOM tree. However, this requires  
>>> extra code for every event handler. Besides, these events were  
>>> often not meant to be generated in the first place, by the intent  
>>> of the author.
>>>
>>> I have no statistics for how often mouseover/out are used with  
>>> and without intent of bubbling, but the anecdotal evidence from  
>>> my own experience has never found me wanting it.
>>>
>>> I suggest these two events be added to the web applications spec.
>>>
>>> [1] http://msdn.microsoft.com/workshop/author/dhtml/reference/ 
>>> events/onmouseenter.asp
>>> [2] http://msdn.microsoft.com/workshop/author/dhtml/reference/ 
>>> events/onmouseleave.asp
>>>
>
>> Can't you just return false from an event handler to prevent  
>> further bubbling?
>>
>
> As mentioned there are workarounds, although I don't think  
> attempting to add anti-bubbling handlers on every descendant  
> element is a reliable one. This unwanted bubbling puts extra load  
> on the user agent for processing it, and the script author to work  
> around it, when removing the root cause is easily possible by  
> making the event non-bubbling to begin with.
>
> -- 
> Magnus Kristiansen
> "Don't worry; the Universe IS out to get you."
Received on Thursday, 15 March 2007 12:10:33 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 16:58:53 UTC