Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

jQuery mouseleave() method

jQuery mouseleave() method

jQuery event methods jQuery event methods

Example

When the mouse pointer leaves the

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 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 also triggered when the mouse pointer leaves any child element. See the demo at the bottom of the page.

**Tip:** This event is usually used together with the mouseenter event.


Syntax

Trigger the mouseleave event of the selected element:

$(

selector

).mouseleave()

Try it

Add a function to the mouseleave event:

$(

selector

).mouseleave(

function

)

Try it

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

More examples

The difference between mouseleave() and mouseout()
Demonstrate the difference between mouseleave() and mouseout().


jQuery event methods jQuery event methods