Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

jQuery hover() method

jQuery hover() method

jQuery event methods jQuery event methods

Example

When the mouse pointer hovers over it, change the

elements' background color:

$

(

"

p

"

)

.

hover

(

function

(

)

{

$

(

"

p

"

)

.

css

(

"

background-color

"

,

"

yellow

"

)

;

}

,

function

(

)

{

$

(

"

p

"

)

.

css

(

"

background-color

"

,

"

pink

"

)

;

}

)

;

Try it »


Definition and Usage

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

method triggers mouseenter and mouseleave events.

Note: If only one function is specified, it is 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 the mouseenter and mouseleave events.

Call:

$(selector).hover(handlerInOut)

Equivalent to:



$( selector ).on( "mouseenter mouseleave", handlerInOut );

Parameters 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 event methods jQuery event methods