跳转到主要内容

Element: gotpointercapture event

{{APIRef("Pointer Events")}}

The gotpointercapture event is fired when an element captures a pointer using setPointerCapture().

Syntax

Use the event name in {{domxref("EventTarget/addEventListener", "addEventListener()")}}:

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

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

ongotpointercapture = (event) => { }

Event type

A {{domxref("PointerEvent")}}. Inherits from {{domxref("Event")}}.

{{InheritanceDiagram("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.

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):

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

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

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

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}

See also