jQuery mouseleave()Method
Examples
When the mouse pointer leaves the <p> element, set the background color to gray:
Try it »
Definition and Usage
The mouseleave event occurs when the mouse pointer leaves the selected element.
The mouseleave() method triggers the mouseleave event, or adds a function to run when the mouseleave event occurs.
Note:andmouseoutThe events are different: the mouseleave event is only triggered when the mouse pointer leaves the selected element, while the mouseout event is also triggered when the mouse pointer leaves any child element. See the demo example at the bottom of the page.
Tip:This event is usually used together with themouseenterevent.
Syntax
Trigger the mouseleave event for the selected element:
Add a function to the mouseleave event:
| Parameters | Description |
|---|---|
| function | Optional. Specifies a function to run when the mouseleave event is triggered. |
More Examples
The difference between mouseleave() and mouseout()
Demonstrates the difference between mouseleave() and mouseout().
Other Extensions
jQuery Event Methods