Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is the target property of the mousewheel event different from that of other (click, mousedown, touchstart) events?

The mousewheel event's target property provides the DOM element that the mouse is currently hovering over as the mousewheel (or gesture-capable touchpad) is being operated.

When I do this (at least in Safari 6, I will test other browsers later) I will get the text node itself as target.

This never happens with other events which always produce a non text node even if I perform the action directly over text.

Needless to say it makes the code more complex than otherwise.

Is there a reason for this? I'd like to avoid having to check the parent node, though thankfully the nice thing about this situation is that I would only ever need to check the target node's parent.

I can't decide if this is a feature or a bug.

like image 584
Steven Lu Avatar asked Jan 01 '13 10:01

Steven Lu


1 Answers

Here's a snippet of the jQuery code where they normalize this behaviour because it's a bug:

// Target should not be a text node (#504, Safari)
if ( event.target.nodeType === 3 ) {
    event.target = event.target.parentNode;
}
like image 160
pimvdb Avatar answered Oct 25 '22 12:10

pimvdb