jQuery hover()Method
Example
When the mouse pointer hovers over it, change the background color of the <p> element:
$("p").hover(function(){
$("p").css("background-color","yellow");
},function(){
$("p").css("background-color","pink");
});
Try it yourself »
Definition and Usage
The hover() method specifies two functions to run when the mouse pointer hovers over the selected element.
The method triggersmouseenterandmouseleaveevents.
Note:If only one function is specified, it will be executed for both mouseenter and mouseleave.
Syntax
$(selector).hover(inFunction,outFunction)
Call:
$( selector ).hover( handlerIn, handlerOut )
Equivalent to the following:
$( 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. Specifies the function to run when the mouseenter event occurs. |
| outFunction | Optional. Specifies the function to run when the mouseleave event occurs. |
Other Extensions
jQuery Event Methods