CKTIS / HTML
onmouseleave — handling the mouse leaving an element
The global HTML onmouseleave attribute contains JavaScript that handles the mouseleave event. It lets an element respond when the mouse pointer leaves the element and its descendants.
Version: WHATWG HTML Living Standard; index snapshot date recorded separately
Syntax
onmouseleave="JavaScript statements"onmouseleave is a global HTML event handler attribute. Its value is a JavaScript function body, not a URL or a complete function declaration. It corresponds to mouseleave, which fires when the mouse pointer leaves the element and its descendants.
Unlike mouseout, mouseleave does not bubble. Moving the pointer from an element into one of its descendants does not mean leaving the whole element. This distinction matters with nested elements.
Inside the attribute code, this refers to the element handling the event, and event provides the event object. The JavaScript property element.onmouseleave accepts a function or null; do not assign code text to it as you would to the HTML attribute.
The example changes the text to Left after the pointer leaves the bordered area. JavaScript must be enabled; Content Security Policy can block inline event handler code. Do not insert untrusted text into such code.
Examples
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>onmouseleave demo</title>
<div onmouseleave="this.textContent = 'Left';" style="padding: 2rem; border: 2px solid;">
Move the mouse here, then outside.
</div>
</html>Result
Left
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.