Latest web development tutorials

jQuery hover () method

jQuery Event Methods jQuery Event Methods

Examples

When the mouse pointer is over the top, change the background color <p> element:

$ ( "P"). Hover (function () {
. $ ( "P") css ( "background-color", "yellow");
}, Function () {
. $ ( "P") css ( "background-color", "pink");
});

try it"

Definition and Usage

hover () method specifies two functions when the mouse pointer is over the selected elements to run.

before jQuery 1.7 version of this method triggers mouseenter and mouseleave events.

After jQuery 1.8 version of this method triggers mouseover and mouseout events.


grammar

$ (Selector) .hover (inFunction,outFunction)

transfer:

$( selector ).hover( handlerIn, handlerOut )

Equivalents as follows:

$( selector ).mouseover( handlerIn ).mouseout( handlerOut );

NOTE: If only specifies a function, it will run on mouseover and mouseout events.

transfer:

$(selector).hover(handlerInOut)

Equivalent to:

$( selector ).on( "mouseover mouseout", handlerInOut );

parameter description
inFunction Required. Prescribed function run when mouseover event occurs.
outFunction Optional. Prescribed function run when mouseout event occurs.


jQuery Event Methods jQuery Event Methods