Bug Tracker

Opened 9 years ago

Closed 8 years ago

Last modified 8 years ago

#6880 closed enhancement (duplicate)

Add compatibility to be able to 'trigger' mouseleave/mouseenter special events w/ bubbling

Reported by: kingjeffrery Owned by:
Priority: high Milestone: 1.5
Component: event Version: 1.4.4
Keywords: trigger mouseenter mouseleave live delegate Cc:
Blocked by: Blocking:

Description

trigger('mouseenter') and trigger('mouseleave') properly triggers events associated with bind(), but not do not trigger events associated with live() or delegate(). Every other event triggers all three.

There are a handful of tickets reporting this as it relates to live(), but there is nothing reporting it for the delegate().

Example code:

HTML: <div class="example"><span>Example</span></div>

JS:

$('.example span').bind('mouseenter', function(){ alert('live'); }); $('.example span').live('mouseenter', function(){ alert('live'); }); $('.example').delegate('span', 'mouseenter', function(){ alert('delegate'); }); $('.example span').trigger('mouseenter');

Only the 'live' alert will fire.

Change History (12)

comment:1 Changed 9 years ago by kingjeffrery

This – of course – also means that .trigger('hover') does not trigger .live() or .delegate() events (since hover is mapped to mouseenter and mouseleave).

comment:2 Changed 9 years ago by kingjeffrery

An example page, demonstrating .trigger() work with every event other than mouseenter, mouseleave and hover can be found here: http://test.kingdesk.com/jquery/bind_live_delegate.php

comment:3 Changed 9 years ago by dmethvin

Since mouseenter and mouseleave don't bubble, any live or delegate attempt higher up the tree wouldn't work. However, a mouseover or mouseout event should work there.

http://www.quirksmode.org/dom/events/mouseover.html

Does that explain the behavior you're reporting? If so, do we just need to explicitly document that?

comment:4 Changed 9 years ago by kingjeffrery

@dmethvin

That would explain things if the mouseenter and mouseleave events were unsupported for live and delegate; but they are supported. The non-bubbling has been overcome for these events when it comes to checking its ancestors for delegated events. But in this case, .trigger() will trigger every event (whether bubbling or not, whether live, deleate or bind) except for mouseenter and mouseleave (and hover which depends on these two events).

Stated another way... I can trigger the mouseenter event that is delegated to an ancestor by moving my mouse over it. I can not trigger the same event with the .trigger() method. If the problem is simply "the event doesn't bubble, so it is not supported", I should not be able to trigger the event physically. But the lack of bubbling has been overcome for live and delegate, and is thus supported in those methods. It is therefore a significant inconsistency to not support it with the .trigger() method.

comment:5 Changed 8 years ago by SlexAxton

Milestone: 1.4.31.5
Priority: high
Status: newopen
Summary: trigger('mouseenter') and trigger('mouseleave') do not trigger events associated with bind() or delegate()Add compatibility to be able to 'trigger' mouseleave/mouseenter special events w/ bubbling
Type: bugenhancement

Yea, it seems like an inconsistency, I agree, to not allow these to be triggered and then force the bubble. I think though, it was not unintentional, at least at the time they became supported in delegate and live, that they were not compatible with trigger. I'm not sure exactly why, but it doesn't seem like it's something they'd forget.

I'll push this in as a high priority feature request, since jQuery doesn't really document these special events being triggerable in either direction.

Until then, you can always trigger the event directly on the container and set the event.target to what you need... not beautiful, but would work in the meantime.

comment:6 Changed 8 years ago by SlexAxton

Resolution: duplicate
Status: openclosed

Setting this as a dupe

comment:7 Changed 8 years ago by SlexAxton

Duplicate of #5884.

comment:8 Changed 8 years ago by SlexAxton

Resolution: duplicate
Status: closedreopened

Was not a dupe. Sorry. Will look more closely next time. But related to 5884, slightly.

comment:9 Changed 8 years ago by addyosmani

#7307 is a duplicate of this ticket.

comment:10 Changed 8 years ago by snover

Status: reopenedopen
Version: 1.4.21.4.4

comment:11 Changed 8 years ago by Rick Waldron

Resolution: duplicate
Status: openclosed

comment:12 Changed 8 years ago by Rick Waldron

Duplicate of #6514.

Note: See TracTickets for help on using tickets.