Steven Lu
Steven Lu

Reputation: 43447

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.

Upvotes: 6

Views: 1277

Answers (1)

pimvdb
pimvdb

Reputation: 154858

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;
}

Upvotes: 5

Related Questions