Easy Tutorial
❮ Jq Event Currenttarget Jquery Dom Set ❯

jQuery hover() Method

jQuery Event Methods

Example

Change the background color of a <p> element when the mouse pointer hovers over it:

$("p").hover(function(){
    $("p").css("background-color","yellow");
},function(){
    $("p").css("background-color","pink");
});

Definition and Usage

The hover() method specifies two functions to run when the mouse pointer hovers over the selected element.

The method triggers the mouseenter and mouseleave events.

Note: If only one function is specified, it will be executed for both mouseenter and mouseleave events.


Syntax

Call:

$( selector ).hover( handlerIn, handlerOut )

Equivalent to:

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

Note: If only one function is specified, it will run on both mouseenter and mouseleave events.

Call:

$(selector).hover(handlerInOut)

Equivalent to:

$( selector ).on( "mouseenter mouseleave", handlerInOut );
Parameter Description
inFunction Required. The function to run when the mouseenter event occurs.
outFunction Optional. The function to run when the mouseleave event occurs.

jQuery Event Methods

❮ Jq Event Currenttarget Jquery Dom Set ❯