JavaScript Element lostpointercapture Event

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

What You’ll Learn

The lostpointercapture event fires when a captured pointer is released. Learn addEventListener vs onlostpointercapture, pointerId, the gotpointercapture pair, releasePointerCapture(), drag cleanup patterns, and five try-it labs.

01

Kind

Instance event

02

Type

PointerEvent

03

When

Capture released

04

Handler

onlostpointercapture

05

Pair

gotpointercapture

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 capture ends, the browser fires lostpointercapture on the element that had captured the pointer. That is your cue to leave “dragging” mode: clear classes, reset cursors, and stop treating moves as part of the session.

💡
Beginner tip

Capture usually starts with setPointerCapture(pointerId) inside pointerdown. Capture ends when you call releasePointerCapture(pointerId), or when the pointer goes up / cancels. Always pair gotpointercapture (start) with lostpointercapture (end) for reliable UI state.

Understanding lostpointercapture

An instance event that answers: “Did this element just lose pointer capture?”

  • Fires when a previously captured pointer is released.
  • PointerEvent — includes pointerId, pointerType, and more.
  • Handleronlostpointercapture or addEventListener("lostpointercapture", ...).
  • Pairgotpointercapture when capture begins.
  • Related APIssetPointerCapture, releasePointerCapture, hasPointerCapture.
  • Baseline Widely available on MDN (since July 2020).

📝 Syntax

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

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

onlostpointercapture = (event) => { };

Event type

A PointerEvent (inherits from MouseEvent and Event).

Handy properties

PropertyMeaning
pointerIdUnique id for the pointer that was released from capture
pointerTypeDevice kind: "mouse", "pen", "touch", …
isPrimaryWhether this is the primary pointer of that type
targetThe element that lost 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—use it for cleanup.

⚖️ 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 gotpointercapture, setPointerCapture(), releasePointerCapture(), and hasPointerCapture() in this Element section.

⚡ Quick Reference

GoalCode / note
Listenel.addEventListener("lostpointercapture", fn)
Handler propertyel.onlostpointercapture = fn
Start captureel.setPointerCapture(event.pointerId) on pointerdown
Cleanup UIReact in lostpointercapture (remove class, reset cursor, clear flag)
End capture earlyel.releasePointerCapture(event.pointerId)
MDN statusBaseline Widely available

🔍 At a Glance

Four facts to remember about lostpointercapture.

Event type
PointerEvent

MouseEvent + Event

Means
lost capture

Pointer released

Key field
pointerId

Identify the pointer

Baseline
yes

Widely available

Examples Gallery

Examples follow MDN Element: lostpointercapture event. Press and hold on the stage, then release to see capture end.

📚 Getting Started

MDN listener patterns and the handler property.

Example 1 — Log When Capture Is Released (MDN)

Capture on pointerdown; listen for lostpointercapture when the pointer is released.

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

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

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

How It Works

Pressing starts capture; lifting the pointer ends it and fires lostpointercapture. Without an earlier setPointerCapture, this listener will not run from a normal click.

Example 2 — onlostpointercapture Property (MDN)

Same idea using the handler property form.

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

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

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, Early Release & Pair

Inspect PointerEvent fields, end capture early, and pair with gotpointercapture.

Example 3 — Log pointerId and pointerType on Release

Show which pointer was released when capture ends.

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

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

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

How It Works

Match pointerId against any id you stored when capture started, so multi-touch sessions clean up the right finger or pen.

Example 4 — End Capture Early with releasePointerCapture

Press to capture, then click End to release without waiting for pointerup.

JavaScript
const stage = document.getElementById("stage");
const endBtn = document.getElementById("end");
const out = document.getElementById("out");
let activeId = null;

stage.addEventListener("lostpointercapture", (event) => {
  out.textContent = "LOST capture id=" + event.pointerId;
  activeId = null;
  stage.classList.remove("is-captured");
});

stage.addEventListener("pointerdown", (event) => {
  activeId = event.pointerId;
  stage.setPointerCapture(event.pointerId);
  stage.classList.add("is-captured");
  out.textContent = "captured id=" + event.pointerId;
});

endBtn.addEventListener("click", () => {
  if (activeId != null && stage.hasPointerCapture(activeId)) {
    stage.releasePointerCapture(activeId);
  }
});
Try It Yourself

How It Works

Early release is useful for Cancel buttons, Escape handlers, or finishing a gesture while the pointer is still down. lostpointercapture still fires.

Example 5 — Pair with gotpointercapture

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.classList.add("is-captured");
});

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

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). Cleanup belongs on lostpointercapture.

🚀 Common Use Cases

  • Leave “dragging” mode (remove classes, restore cursor).
  • Finalize slider / scrubber values when the pointer lifts.
  • Stop canvas drawing strokes when capture ends.
  • Cancel or commit a custom resize / pan gesture.
  • Debug capture sessions with pointerId release logs.

🔧 How It Works

1

pointerdown + setPointerCapture

Element starts capturing an active pointer.

Start
2

gotpointercapture

Capture confirmed; moves retarget to this element.

Event
3

pointerup / releasePointerCapture

Capture ends automatically or by API call.

Release
4

lostpointercapture

Session closed—clean up UI and flags.

📝 Notes

  • MDN: Baseline Widely available — no Deprecated / Experimental / Non-standard banner.
  • Capture needs an earlier successful setPointerCapture for lostpointercapture to be meaningful.
  • Also listen for pointercancel paths; capture can end without a clean pointerup.
  • Use touch-action: none on drag surfaces to reduce browser gesture interference.
  • Related learning: gotpointercapture, pointercancel, releasePointerCapture(), addEventListener(), JavaScript hub.

Browser Support

lostpointercapture is marked Baseline Widely available on MDN (since July 2020). 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 lostpointercapture

Fires when a captured pointer is released; pair with gotpointercapture 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
lostpointercapture Baseline

Bottom line: Safe to use for modern drag UX cleanup. Always handle release and cancel paths, and test touch + mouse.

Conclusion

lostpointercapture tells you that pointer capture has ended. Use it to leave a drag session cleanly after gotpointercapture started it.

Continue with mousedown, gotpointercapture, releasePointerCapture(), or the JavaScript hub.

💡 Best Practices

✅ Do

  • Listen for gotpointercapture / lostpointercapture as a pair
  • Clean up UI and flags inside lostpointercapture
  • Use hasPointerCapture before calling releasePointerCapture
  • Handle both pointerup and cancel / early-release paths
  • Prefer addEventListener for production code

❌ Don’t

  • Leave drag classes on forever because you only handled pointerup
  • Ignore multi-touch pointerId matching when cleaning up
  • Forget pointercancel can also end capture
  • Overwrite onlostpointercapture if you need multiple listeners
  • Assume capture without an earlier successful setPointerCapture

Key Takeaways

Knowledge Unlocked

Five things to remember about lostpointercapture

Capture ended—clean up the drag session.

5
Core concepts
📄 02

PointerEvent

pointerId · type

API
👆 03

Cleanup UX

reset drag UI

Why
🔄 04

gotpointercapture

session opened

Pair
🎯 05

Baseline

widely available

Status

❓ Frequently Asked Questions

It fires when a captured pointer is released. Capture can end via releasePointerCapture(), pointerup, pointercancel, or other release paths. Use it to clean up drag UI and session state.
No. MDN marks Element lostpointercapture 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.
After pointer capture ends for that element — for example when you call releasePointerCapture(pointerId), or when the pointer is released (pointerup) while capture was active.
gotpointercapture fires when setPointerCapture() succeeds and capture begins. lostpointercapture is the matching end signal.
So you can reset cursors, remove dragging classes, stop tracking moves, and restore idle UI when the capture session ends — even if the pointer left the element.
Did you know?

You can end capture early with releasePointerCapture() even while the pointer is still down. The browser still fires lostpointercapture, so your cleanup path stays in one place.

Next: mousedown

Learn the MouseEvent that fires when a pointing-device button is pressed.

mousedown →

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