jQuery hover()Method

jQuery 事件方法jQuery Event Methods

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.


jQuery 事件方法jQuery Event Methods

Other Extensions