Description
The .hover() method binds functions to the mouseenter and mouseleave event.
Bind Functions to the hover Event
Specifies a function to run when the mouseenter and mouseleave events occur.
Note: If only one function is specified, it will be run for both the mouseenter and mouseleave event.
v1.0
This method has the form:
.hover(inFunction,outFunction)
Parameter | Description |
---|---|
inFunction | (required) Specifies the function to run when the mouseenter event occurs. If this is the only parameter specified, this function will be run for both the mouseenter and mouseleave events. |
outFunction | (optional) Specifies the function to run when the mouseleave event occurs |
Return Value
This form returns a jQuery object.
v1.4
This method has the alternate form:
.hover(inOutFunction)
Parameter | Description |
---|---|
inOutFunction | (required) Specifies the function to run when the mouseenter or mouseleave event occurs |
Return Value
This form returns a jQuery object.
Examples
Change background color of an element when the mouse pointer enters or leaves it:
$("p").hover(function(){
$("p").css("background-color","yellow");
},function(){
$("p").css("background-color","#E9E9E4");
});