Ticket #12140 (closed bug: duplicate)
Incorrect event type reported on hover within a setTimeout
| Reported by: | Motty | Owned by: | |
|---|---|---|---|
| Priority: | undecided | Milestone: | None |
| Component: | unfiled | Version: | git |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
When I add a setTimeout within a hover function, the e.type returns "mouseover" and "mouseout" instead of "mouseenter" and "mouseleave".
jsFiddle: http://jsfiddle.net/Mottie/P6gCg/1/
$('#test').hover(function(e){
console.log(e.type);
setTimeout(function(){
console.log('after timeout: ' + e.type);
}, 0);
});
This problem occurs in jQuery v1.6.4+. Versions prior to this report the correct event type.
Change History
comment:1 Changed 10 months ago by rwaldron
- Status changed from new to closed
- Resolution set to duplicate
comment:3 Changed 10 months ago by Motty
Hmm, ok I get the same incorrect event types when I bind to "mouseenter" and "mouseleave" ( http://jsfiddle.net/Mottie/P6gCg/3/):
$('#test').bind('mouseenter mouseleave', function(e){
console.log(e.type);
setTimeout(function(){
console.log('after timeout: ' + e.type);
}, 0);
});
Again, this happens in jQuery 1.6.4+
comment:4 Changed 10 months ago by dmethvin
The event object is valid only for the duration of the event. After it returns you can't expect it to remain unchanged. In fact, the entire native event object (event.originalEvent) cannot be read in IE6/7/8 after the event has passed--it's gone and will throw an error if you try to access it. If you need an unchanging copy of some event data, make one.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.
