jQuery - hover() method

The hover() is called for both eventsmouseenter and mouseleave. You can use it to detect when the mouse goes under an element.

.hover( handlerIn, handlerOut )

The method  hover()  is a shorthand of :

$( selector ).mouseenter( handlerIn ).mouseleave( handlerOut ); 
Syntax:

$( selector ).hover( handlerIn, handlerOut )
Example:

$( "p" ).hover(
function() { // Mouse enters the
$( this ).addClass( "hover" );
}, function() { // Mouse exits zone
$( this ).removeClass( "hover" );
}
);

.hover( handlerInOut )

This method is useful when the same processing is repeated for both the input and output events of the target element area. We won't need to copy the code into both the input and output event functions.

Syntax:

$(selector).hover(handlerInOut)
When passing a single function to the hover(), it will execute two events, mouseenter and mouseleave. This allows the jQuery user to use the different failover methods in the handler or respond differently depending on event.type.

Example:

$( selector ).on( "Mouse pointer in and out of box", handlerInOut ); 

References:
https://api.jquery.com/hover/

Commentaires (12)

Connectez-vous pour commenter

Rejoignez la discussion et partagez vos connaissances avec la communauté

JD
Jean Dupont Il y a 2 heures

Excellent tutoriel ! J'ai enfin compris comment utiliser Apache POI correctement.

👍 12 Répondre Signaler
CodeurJava ✓ Auteur • Il y a 1 heure

Merci Jean ! N'hésitez pas si vous avez des questions.