Skip to main content

Bug Tracker

Side navigation

#6880 closed enhancement (duplicate)

Opened August 06, 2010 03:54AM UTC

Closed January 02, 2011 12:46AM UTC

Last modified January 02, 2011 12:46AM UTC

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.

Attachments (0)
Change History (12)

Changed August 06, 2010 06:43AM UTC by kingjeffrery comment:1

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

Changed August 06, 2010 07:31PM UTC by kingjeffrery comment:2

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

Changed August 07, 2010 03:26AM UTC by dmethvin comment:3

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?

Changed August 11, 2010 04:32PM UTC by kingjeffrery comment:4

@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.

Changed October 25, 2010 07:06AM UTC by SlexAxton comment:5

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.

Changed October 25, 2010 07:49AM UTC by SlexAxton comment:6

resolution: → duplicate
status: openclosed

Setting this as a dupe

Changed October 25, 2010 07:49AM UTC by SlexAxton comment:7

Duplicate of #5884.

Changed October 25, 2010 07:50AM UTC by SlexAxton comment:8

resolution: duplicate
status: closedreopened

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

Changed October 25, 2010 08:58PM UTC by addyosmani comment:9

#7307 is a duplicate of this ticket.

Changed November 22, 2010 07:07AM UTC by snover comment:10

status: reopenedopen
version: 1.4.21.4.4

Changed January 02, 2011 12:46AM UTC by rwaldron comment:11

resolution: → duplicate
status: openclosed

Changed January 02, 2011 12:46AM UTC by rwaldron comment:12

Duplicate of #6514.