jQuery hover() method attaches mouse hover event listener to the HTML Element.
jQuery hover is a compound event. In includes mouse-enter and mouse-leave event. jQuery hover() method accepts two functions as arguments. First function is executed when mouse enter event is occured and the second function is executed when the mouse leave event is triggered.
Syntax – hover()
Following is the syntax to use jQuery hover() method to attach a mouse hover event listener to HTML Element(s).
Examples – jQuery hover()
1. Example – Change text of paragraphs when mouse hovers on them
In the following example, when mouse hover occurs, mouse enter and mouse leave events trigger respective functions provided as arguments to hover() function.
2. Example – Change DIV’s background color when mouse hovers it
Following example has a div on which mouse hover event is attached. When mouse hovers on the div, background color of it is changed.
In this jQuery Tutorial, we have learnt jQuery hover() method : Syntax and Usage with examples.