jQuery mouseleave()Method

jQuery 事件方法jQuery Event Methods

Examples

When the mouse pointer leaves the <p> element, set the background color to gray:

$("p").mouseleave(function(){ $("p").css("background-color","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:

$(selector).mouseleave() Try it

Add a function to the mouseleave event:

$(selector).mouseleave(function) Try it

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().


jQuery 事件方法jQuery Event Methods

Other Extensions