Element: gotpointercapture 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 gotpointercapture event is fired when an element captures a pointer using setPointerCapture().

Syntax

Use the event name in addEventListener():

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

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

js
ongotpointercapture = (event) => { }

Event type

A PointerEvent. Inherits from Event.

Event UIEvent MouseEvent PointerEvent

Examples

This example gets a <p> element and listens for the gotpointercapture event. It then calls setPointerCapture() on the element on a pointerdown event, which will trigger gotpointercapture.

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

para.addEventListener("gotpointercapture", () => {
  console.log("I've been captured!");
});

para.addEventListener("pointerdown", (event) => {
  para.setPointerCapture(event.pointerId);
});

The same example, using the ongotpointercapture event handler property (but note that this replaces other event listeners added using ongotpointercapture, if any):

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

para.ongotpointercapture = () => {
  console.log("I've been captured!");
};

para.addEventListener("pointerdown", (event) => {
  para.setPointerCapture(event.pointerId);
});

Specifications

Specification
Pointer Events
# gotpointercapture
Pointer Events
# dom-globaleventhandlers-ongotpointercapture

Browser compatibility

See also