Bug Tracker

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#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:
Blocked by: Blocking:

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 (4)

comment:1 Changed 7 years ago by Rick Waldron

Resolution: duplicate
Status: newclosed

comment:2 Changed 7 years ago by Rick Waldron

Duplicate of #11690.

comment:3 Changed 7 years 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+

Last edited 7 years ago by Motty (previous) (diff)

comment:4 Changed 7 years 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.

Note: See TracTickets for help on using tickets.