Bug Tracker

Modify

Ticket #5884 (closed bug: fixed)

Opened 4 years ago

Last modified 3 years ago

live mouseenter/mouseleave events don't fire as expected when nested

Reported by: oyejorge Owned by: brandon
Priority: low Milestone: 1.6
Component: event Version: 1.4
Keywords: live mouseenter mouseleave Cc:
Blocking: Blocked by:

Description

I found that when using the mouseenter/mouseleave events with the .live() method, the results were not the same as if I used the .bind() method.

When using the bind() method a nested mouseenter will not trigger the outer mouseleave. But when using live() the outer mouseleave will be triggered.

See attached test document.

Thanks for this amazing product!

Attachments

mouseenter.html Download (1.2 KB) - added by oyejorge 4 years ago.
Shows differences between bind() and live() with mouseenter/mouseleave

Change History

Changed 4 years ago by oyejorge

Shows differences between bind() and live() with mouseenter/mouseleave

comment:1 Changed 4 years ago by Licensed to Gil

I've also found this issue and narrowed it down - it only occurs when the parent and child elements have the events bound with the same selector.

Example:

// Problem occurs:
$('#outer, #inner').live('mouseenter mouseleave', handler);

// No problem:
$('#outer').live('mouseenter mouseleave', handler);
$('#inner').live('mouseenter mouseleave', handler);

Basically, the live event handler code in jQuery is only checking if the selectors are different instead of checking the parent/child relationship.

I've got a quick patch here:

 http://github.com/gilmoreorless/jquery/commit/7774ed588fa04006cad2c729122816af6b019f2c

Cheers,

Gil

comment:2 Changed 3 years ago by SlexAxton

  • Priority changed from major to low
  • Status changed from new to open
  • Milestone changed from 1.4 to 1.5

comment:3 Changed 3 years ago by john

  • Milestone set to 1.6

comment:4 Changed 3 years ago by Gilmore Davidson

  • Status changed from open to closed
  • Resolution set to fixed

Added check for live mouseenter/mouseleave events if bound to nested elements with the same selector. Fixes #5884.

Changeset: a9b81d759af3a4574a42ca1de93be1247f7953a2

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.