Bug Tracker

Opened 8 years ago

Closed 8 years ago

Last modified 7 years ago

#11690 closed bug (invalid)

.on('hover' ..) shows two different event types for when logging event and event.type

Reported by: christianlaustsen@… Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.7.2
Keywords: Cc:
Blocked by: Blocking:

Description

This was tested in Google Chrome v. 18.0.1025.168 if that matters :)

Using this code:

$(document).on('hover', '.item', function(event) {
    console.log(event);
    console.log(event.type);
});

On mouseenter it shows: Output from event: jQuery.Event

... toElement: HTMLImageElement type: "mouseover" ...

Output from event.type: mouseenter

On mouse out it does: Output from event: jQuery.Event

... toElement: HTMLImageElement type: "mouseout" ...

Output from event.type: mouseleave

When trying to catch the event, it only responds to mouseenter/mouseleave and not mouseover/mouseout.

Example, this runs console.log():

$(document).on('hover', '.item', function(event) {
    if (event.type == "mouseenter") {
        console.log('Success');
    }
});

while this doesn't:

$(document).on('hover', '.item', function(event) {
    if (event.type == "mouseover") {
        console.log('Success');
    }
});

You can send me an email if you have any further questions.

Change History (3)

comment:1 Changed 8 years ago by Rick Waldron

Resolution: invalid
Status: newclosed

hover is not a real event, it's a cover API for mousenter/mouseleave.

http://api.jquery.com/hover/

comment:2 Changed 8 years ago by dmethvin

http://api.jquery.com/on

Although strongly discouraged for new code, you may see the pseudo-event-name "hover" used as a shorthand for the string "mouseenter mouseleave". It attaches a single event handler for those two events, and the handler must examine event.type to determine whether the event is mouseenter or mouseleave. Do not confuse the "hover" pseudo-event-name with the .hover() method, which accepts one or two functions.

comment:3 Changed 7 years ago by Rick Waldron

#12140 is a duplicate of this ticket.

Note: See TracTickets for help on using tickets.