Easy Tutorial
❮ Misc Promise Jquery Selectors ❯

jQuery mouseleave() Method

jQuery Event Methods

Example

Set the background color to gray when the mouse pointer leaves the <p> element:

$("p").mouseleave(function(){
    $("p").css("background-color","gray");
});

Definition and Usage

The mouseleave event occurs when the mouse pointer leaves the selected element.

The mouseleave() method triggers the mouseleave event, or attaches a function to run when a mouseleave event occurs.

Note: Unlike the mouseout event, the mouseleave event is only triggered when the mouse pointer leaves the selected element, while the mouseout event is triggered when the mouse pointer leaves any child element as well. See the demo at the bottom of the page.

Tip: This event is often used together with the mouseenter event.


Syntax

Trigger the mouseleave event for the selected elements:

Attach a function to the mouseleave event:

Parameter Description
function Optional. Specifies the function to run when the mouseleave event is triggered.

More Examples

Difference between mouseleave() and mouseout()


jQuery Event Methods

❮ Misc Promise Jquery Selectors ❯