Ticket #7037 (closed bug: fixed)
Duplicate mouseover and mouseout events added to cloned element.
| Reported by: | patrickwhalen | Owned by: | dmethvin |
|---|---|---|---|
| Priority: | blocker | Milestone: | 1.7 |
| Component: | manipulation | Version: | 1.4.2 |
| Keywords: | clone,events,mouseover,mouseout,1.7-discuss | Cc: | |
| Blocking: | Blocked by: |
Description (last modified by dmethvin) (diff)
When cloning an element that has mouseenter or mouseleave events, the clone will receive a duplicate mouseover and mouseout event causing the handler to double-fire.
So if the jQuery.cache shows this for the original:
mouseenter: Array(1)
mouseover: Array(1)
mouseleave: Array(1)
mouseout: Array(1)
the clone will have:
mouseenter: Array(1)
mouseover: Array(2)
mouseleave: Array(1)
mouseout: Array(2)
Test: http://jsfiddle.net/9y7tp/
The hover for the original element will toggleClass the "blue" class properly and show one alert.
The hover for the clone double-fires the handler, so the toggleClass is called again, and you get 2 alerts.
var $hoverbox = $('.hover').hover(function(e) {
$('#box').toggleClass('blue');
alert(e.type);
});
$hoverbox.clone(true).text("Hover clone").appendTo('body');
Change History
comment:3 Changed 3 years ago by snover
- Milestone changed from 1.4.3 to 1.4.5
Retargeting for next release.
comment:4 Changed 2 years ago by rwaldron
- Owner set to rwaldron
- Status changed from open to assigned
comment:8 Changed 2 years ago by john
- Owner changed from rwaldron to dmethvin
- Milestone changed from 1.next to 1.6
comment:9 Changed 2 years ago by john
- Milestone changed from 1.6 to 1.next
Let's bump this and discuss it for 1.7.
comment:10 Changed 2 years ago by john
- Keywords clone,events,mouseover,mouseout,1.7-discuss added; clone events mouseover mouseout removed
Nominating ticket for 1.7 discussion.
comment:11 Changed 2 years ago by rwaldron
- Description modified (diff)
+1, Seems like a bug, should be fixed
comment:12 Changed 2 years ago by jaubourg
+1, It's a bug
comment:15 Changed 2 years ago by john
+1, Oof, let's get this fixed.
comment:16 Changed 2 years ago by scott.gonzalez
+1
comment:17 Changed 2 years ago by jzaefferer
+0
comment:18 Changed 23 months ago by dmethvin
- Description modified (diff)
- Milestone changed from 1.next to 1.7
comment:19 Changed 20 months ago by dmethvin
- Status changed from assigned to closed
- Resolution set to fixed
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

Just noting that this is still an issue in jQuery 1.4.3 rc1