files/en-us/web/api/element/gotpointercapture_event/index.md
{{APIRef("Pointer Events")}}
The gotpointercapture event is fired when an element captures a pointer using setPointerCapture().
Use the event name in methods like {{domxref("EventTarget.addEventListener", "addEventListener()")}}, or set an event handler property.
addEventListener("gotpointercapture", (event) => { })
ongotpointercapture = (event) => { }
A {{domxref("PointerEvent")}}. Inherits from {{domxref("Event")}}.
{{InheritanceDiagram("PointerEvent")}}
This interface inherits properties from {{domxref("MouseEvent")}} and {{domxref("Event")}}.
PointerEvent.0 to 1, where 0 and 1 represent the minimum and maximum pressure the hardware is capable of detecting, respectively.-1 to 1, where 0 is the neutral position of the control.-90 to 90) between the Y–Z plane and the plane containing both the pointer (e.g., pen stylus) axis and the Y axis.-90 to 90) between the X–Z plane and the plane containing both the pointer (e.g., pen stylus) axis and the X axis.0 to 359.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:
const para = document.querySelector("p");
para.ongotpointercapture = () => {
console.log("I've been captured!");
};
para.addEventListener("pointerdown", (event) => {
para.setPointerCapture(event.pointerId);
});
{{Specifications}}
{{Compat}}