JavaScript Element gotpointercapture Event

Beginner
⏱️ 11 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
DOM event
Instance event

What You’ll Learn

The gotpointercapture event fires when an element captures a pointer with setPointerCapture(). Learn addEventListener vs ongotpointercapture, pointerId, the lostpointercapture pair, drag capture patterns, and five try-it labs.

01

Kind

Instance event

02

Type

PointerEvent

03

When

After setPointerCapture()

04

Handler

ongotpointercapture

05

Pair

lostpointercapture

06

Status

Baseline widely available

Introduction

Pointer capture lets an element keep receiving events for a specific pointer even when the pointer leaves that element’s hit area—perfect for sliders, drag handles, and canvas drawing.

When you call setPointerCapture(pointerId) and capture succeeds, the browser fires gotpointercapture on the capturing element. Pair it with lostpointercapture to know when capture ends.

💡
Beginner tip

Capture usually starts inside a pointerdown handler while a button/touch is active. Use event.pointerId from that event when calling setPointerCapture. Set touch-action: none on drag surfaces so the browser does not steal the gesture for scrolling.

Understanding gotpointercapture

An instance event that answers: “Did this element just become the capture target for a pointer?”

  • Fires after a successful setPointerCapture(pointerId).
  • PointerEvent — includes pointerId, pointerType, and more.
  • Handlerongotpointercapture or addEventListener("gotpointercapture", ...).
  • Pairlostpointercapture when capture is released.
  • Related APIssetPointerCapture, releasePointerCapture, hasPointerCapture.
  • Baseline Widely available on MDN.

📝 Syntax

Use the event name with addEventListener, or set the handler property:

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

ongotpointercapture = (event) => { };

Event type

A PointerEvent (inherits from MouseEvent and Event).

Handy properties

PropertyMeaning
pointerIdUnique id for the captured pointer (pass to set/release/has APIs)
pointerTypeDevice kind: "mouse", "pen", "touch", …
isPrimaryWhether this is the primary pointer of that type
targetThe element that gained pointer capture

🔁 Capture Lifecycle

A typical drag / slider flow looks like this:

  1. pointerdown on the element (pointer is active)
  2. setPointerCapture(pointerId) on the element
  3. gotpointercapture fires on the capturing element
  4. pointermove events keep targeting the capturer (even outside bounds)
  5. pointerup / releasePointerCapture()lostpointercapture

So gotpointercapture is the “capture started” confirmation; lostpointercapture is the matching end signal.

⚖️ Capture APIs at a glance

APIRole
setPointerCapture(id)Start capturing; may fire gotpointercapture
gotpointercaptureEvent: capture succeeded on this element
hasPointerCapture(id)Query whether this element currently captures id
releasePointerCapture(id)End capture early; leads to lostpointercapture
lostpointercaptureEvent: capture released for the pointer
🔔
Related tutorials

See also setPointerCapture() and hasPointerCapture() in this Element section.

⚡ Quick Reference

GoalCode / note
Listenel.addEventListener("gotpointercapture", fn)
Handler propertyel.ongotpointercapture = fn
Start captureel.setPointerCapture(event.pointerId) on pointerdown
Confirm captureReact in gotpointercapture (UI badge, log, state flag)
End capturereleasePointerCapture or wait for pointerup
MDN statusBaseline Widely available

🔍 At a Glance

Four facts to remember about gotpointercapture.

Event type
PointerEvent

MouseEvent + Event

Means
got capture

After setPointerCapture

Key field
pointerId

Identify the pointer

Baseline
yes

Widely available

Examples Gallery

Examples follow MDN Element: gotpointercapture event. Press and hold on the stage elements to trigger capture.

📚 Getting Started

MDN listener patterns and the handler property.

Example 1 — Log When Capture Succeeds (MDN)

Call setPointerCapture on pointerdown; listen for gotpointercapture.

JavaScript
const para = document.querySelector("p");
const out = document.getElementById("out");

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

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

How It Works

gotpointercapture confirms capture started. Without setPointerCapture, this listener never runs from a normal press.

Example 2 — ongotpointercapture Property (MDN)

Same idea using the handler property form.

JavaScript
const para = document.querySelector("p");
const out = document.getElementById("out");

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

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

How It Works

Prefer addEventListener when you need multiple listeners or easy removal.

📈 IDs, Drag & Release

Inspect PointerEvent fields, keep moves during drag, and pair with lostpointercapture.

Example 3 — Log pointerId and pointerType

Show which pointer was captured when the event fires.

JavaScript
const stage = document.getElementById("stage");
const out = document.getElementById("out");

stage.addEventListener("gotpointercapture", (event) => {
  out.textContent =
    "captured id=" + event.pointerId +
    " type=" + event.pointerType;
});

stage.addEventListener("pointerdown", (event) => {
  stage.setPointerCapture(event.pointerId);
});
Try It Yourself

How It Works

Store pointerId if you later call releasePointerCapture or hasPointerCapture.

Example 4 — Drag Handle with Capture

Capture on down so pointermove keeps updating even outside the handle.

JavaScript
const handle = document.getElementById("handle");
const out = document.getElementById("out");

handle.addEventListener("gotpointercapture", () => {
  out.textContent = "dragging…";
  handle.classList.add("is-captured");
});

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

handle.addEventListener("pointermove", (event) => {
  if (!handle.hasPointerCapture(event.pointerId)) return;
  handle.style.transform = "translateX(" + (event.clientX - 40) + "px)";
});

handle.addEventListener("pointerup", (event) => {
  if (handle.hasPointerCapture(event.pointerId)) {
    handle.releasePointerCapture(event.pointerId);
  }
});
Try It Yourself

How It Works

Without capture, moving outside the handle can stop updates. Capture keeps the element as the event target until release.

Example 5 — Pair with lostpointercapture

Toggle UI state when capture starts and when it ends.

JavaScript
const stage = document.getElementById("stage");
const out = document.getElementById("out");

stage.addEventListener("gotpointercapture", (event) => {
  out.textContent = "GOT capture id=" + event.pointerId;
});

stage.addEventListener("lostpointercapture", (event) => {
  out.textContent = "LOST capture id=" + event.pointerId;
});

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

stage.addEventListener("pointerup", (event) => {
  if (stage.hasPointerCapture(event.pointerId)) {
    stage.releasePointerCapture(event.pointerId);
  }
});
Try It Yourself

How It Works

Treat these two events as open/close for your drag session UI (highlights, cursors, status text).

🚀 Common Use Cases

  • Confirm a drag session started (show “dragging” UI).
  • Sliders and scrubbers that must track outside their bounds.
  • Canvas / drawing tools that follow the pointer until lift.
  • Custom window / panel resize handles.
  • Debugging capture with pointerId logs.

🔧 How It Works

1

pointerdown

User presses; you receive an active pointerId.

Down
2

setPointerCapture

Element requests to become the capture target.

API
3

gotpointercapture

Browser confirms capture; later moves retarget here.

Event
4

lostpointercapture

Release / pointerup ends the session—clean up UI.

📝 Notes

  • MDN: Baseline Widely available — no Deprecated / Experimental / Non-standard banner.
  • Capture needs an active pointer (button down / touch contact) for setPointerCapture to take effect.
  • Use touch-action: none on drag surfaces to reduce browser gesture interference.
  • If you move the element in the DOM, call setPointerCapture after the move so capture stays attached.
  • Related learning: gesturestart, input, setPointerCapture(), addEventListener(), JavaScript hub.

Browser Support

gotpointercapture is marked Baseline Widely available on MDN. Logos use the shared browser-image-sprite.png sprite from this project. Pointer capture is part of the modern Pointer Events model across engines.

Baseline · Widely available

Element gotpointercapture

Fires when setPointerCapture() succeeds; pair with lostpointercapture for drag sessions.

Full Widely available
Google Chrome 57+
Yes
Mozilla Firefox 59+
Yes
Apple Safari 13+
Yes
Microsoft Edge 17+
Yes
Opera 44+
Yes
Internet Explorer No modern Pointer Events
No
gotpointercapture Baseline

Bottom line: Safe to use for modern drag UX. Always release capture cleanly and test touch + mouse paths.

Conclusion

gotpointercapture tells you that setPointerCapture worked. Use it to enter a drag session, keep listening for moves, and clean up on lostpointercapture.

Continue with input, setPointerCapture(), addEventListener(), or the JavaScript hub.

💡 Best Practices

✅ Do

  • Call setPointerCapture from pointerdown with event.pointerId
  • Listen for gotpointercapture / lostpointercapture as a pair
  • Use hasPointerCapture before releasing
  • Set touch-action: none on drag surfaces
  • Prefer addEventListener for production code

❌ Don’t

  • Assume capture without waiting for gotpointercapture (or checking hasPointerCapture)
  • Forget to release / handle pointerup and pointercancel
  • Move the element in the DOM and expect old capture to stick without re-calling
  • Ignore touch scrolling interference on mobile
  • Overwrite ongotpointercapture if you need multiple listeners

Key Takeaways

Knowledge Unlocked

Five things to remember about gotpointercapture

Capture confirmed—keep pointer events until release.

5
Core concepts
📄 02

PointerEvent

pointerId · type

API
👆 03

Drag UX

moves keep coming

Why
🔄 04

lostpointercapture

session closed

Pair
🎯 05

Baseline

widely available

Status

❓ Frequently Asked Questions

It fires on an element after that element successfully captures a pointer with setPointerCapture(pointerId). From then on, subsequent events for that pointer are retargeted to the capturing element until capture is released.
No. MDN marks Element gotpointercapture as Baseline Widely available. It is not Deprecated, Experimental, or Non-standard.
A PointerEvent (inherits from MouseEvent and Event). Handy fields include pointerId, pointerType, and isPrimary.
Usually call element.setPointerCapture(event.pointerId) inside a pointerdown handler while the pointer is in an active buttons state. When capture succeeds, gotpointercapture fires.
lostpointercapture fires when capture is released — via releasePointerCapture(), pointerup, pointercancel, or similar release paths.
So a drag, slider, or drawing surface keeps receiving pointermove events even if the pointer leaves the element’s bounds.
Did you know?

While pointer capture is active, pointerover / pointerenter / pointerleave / pointerout generally do not fire for hit-testing changes—events are retargeted to the capturing element.

Next: input

Learn the live event that fires when a form control value changes.

input →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful