Element: pointerleave event

Baseline
Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2020.

The pointerleave event is fired when a pointing device is moved out of the hit test boundaries of an element. For pen devices, this event is fired when the stylus leaves the hover range detectable by the digitizer. Otherwise, pointerleave works the same as mouseleave, and are dispatched at the same time. They are also dispatched at the same time as mouseout and pointerout events, if appropriate.

Syntax

Use the event name in addEventListener():

js
addEventListener("pointerleave", (event) => { })

Alternatively, assign to the event handler property of the interface:

js
onpointerleave = (event) => { }

Event type

A PointerEvent. Inherits from Event.

Event UIEvent MouseEvent PointerEvent

Examples

Using addEventListener():

js
const para = document.querySelector("p");

para.addEventListener("pointerleave", (event) => {
  console.log("Pointer left element");
});

Using the onpointerleave event handler property (but note that this replaces other event listeners added using onpointerleave, if any):

js
const para = document.querySelector("p");

para.onpointerleave = (event) => {
  console.log("Pointer left element");
};

Specifications

Specification
Pointer Events
# pointerleave
Pointer Events
# dom-globaleventhandlers-onpointerleave

Browser compatibility

See also