Bug Tracker

Opened 7 years ago

Closed 7 years ago

#13436 closed bug (notabug)

Code-triggered mouseout should not trigger mouseleave on ancestor

Reported by: jaredjacobs@… Owned by:
Priority: low Milestone: None
Component: event Version: git
Keywords: Cc:
Blocked by: Blocking:

Description

If I call $element.mouseout() to run an element's mouseout handler, then jQuery also invokes any mouseleave handlers on the element's ancestors.

This is contrary to what http://api.jquery.com/mouseleave/ says:

The mouseleave event, on the other hand, only triggers its handler when the mouse leaves the element it is bound to, not a descendant.

Change History (4)

comment:1 Changed 7 years ago by Jared Jacobs <jaredjacobs@…>

comment:2 Changed 7 years ago by dmethvin

Component: unfiledevent
Priority: undecidedlow
Status: newopen

The best way to run handlers alone is with .triggerHandler(), doing it with .trigger() (or shortcut methods like .mouseout()) risks running DOM behaviors along with the handler.

This issue has been around since 1.7 so it must not be very commonly encountered. I suspect it's because the synthetic event isn't set up the same as the natural one.

comment:3 Changed 7 years ago by Jared Jacobs <jaredjacobs@…>

Thanks for the feedback. I'm aware of .triggerHandler}}. I'm using a {{{.trigger shortcut method because the mouseout handler I want to run is registered on an ancestor via .on with a selector argument.

Agree that this is low priority, since a simple workaround is to avoid .trigger by using .triggerHandler or by naming the handler and invoking it directly.

comment:4 Changed 7 years ago by dmethvin

Resolution: notabug
Status: openclosed

I looked at this and it the correct behavior for a triggered mouseout event if it's intended to emulate a real mouse event. If you want to just fire the handlers, .triggerHandler() is the right choice.

Note: See TracTickets for help on using tickets.