In JavaScript, the pointerleave event fires when a pointer moves out of an element’s hit test boundaries (MDN). For pen, it also fires when the stylus leaves the digitizer’s detectable hover range.
Register a listener with addEventListener. Check readiness and browser support before you rely on this event.
Syntax
Listen for pointerleave. Start with this line.
JavaScript
addEventListener("pointerleave", fn)
Call
What it does
addEventListener("pointerleave", fn)
Primary signature.
Built into the browser. Listen with el.addEventListener("pointerleave", …) — no import required.
Library declarations
JavaScript
addEventListener("pointerleave", fn)
Parameters
Parameter
Description
Event name
Required. "pointerleave"
Handler prop
Optional. onpointerleave
PointerEvent
Required. pointerId, pointerType, …
Return Value
Return Value
Description
*
Fires as an Element event (listener receives the Event object).
JavaScript Examples
Example 1 — Log pointerleave (MDN)
MDN’s basic listener when a pointer leaves an element.
JavaScript
const para = document.querySelector("p");
para.addEventListener("pointerleave", (event) => {
console.log("Pointer left element", event.pointerType);
});
MDN: it fires when a pointing device moves out of an element’s hit test boundaries. For pen, it also fires when the stylus leaves the digitizer’s detectable hover range.
No. MDN marks Element pointerleave as Baseline Widely available (since July 2020). It is not Deprecated, Experimental, or Non-standard.
A PointerEvent. Useful fields include pointerId, pointerType, isPrimary, clientX, and clientY.
pointerleave does not bubble and is not sent again when the pointer moves between the element and its descendants. pointerout bubbles and fires when moving among descendants.
MDN: otherwise pointerleave works the same as mouseleave and they are dispatched at the same time (along with mouseout / pointerout when appropriate).
MDN (pointerdown): on touchscreens with direct manipulation, implicit pointer capture can suppress pointerover / pointerenter / pointerleave / pointerout until release or releasePointerCapture.