JavaScript Document releaseCapture() Method

Beginner
⏱️ 12 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Non-standard
Instance method

What You’ll Learn

document.releaseCapture() is a Non-standard instance method that turns off mouse capture for the document (see MDN Document: releaseCapture()). Learn how it pairs with element.setCapture(), how to feature-detect safely, and why modern apps use Pointer Events instead — plus five try-it labs.

01

Kind

Instance method

02

Args

None

03

Returns

undefined

04

Pairs with

setCapture()

05

Prefer

Pointer Events

06

Status

Non-standard

Introduction

Sometimes a drag or slider needs every mouse move — even when the pointer leaves the element. Older Gecko-oriented APIs solved that with mouse capture: call element.setCapture() on mousedown, then later call document.releaseCapture() to restore normal event targeting (MDN).

MDN: once capture is released, mouse events will no longer all be directed to the element that held capture. There are no parameters; the return value is undefined.

💡
Think: “Stop routing all mouse events to that element”

1) mousedownel.setCapture() (Non-standard)
2) Mouse moves keep targeting that element
3) document.releaseCapture() (or mouseup / button up) ends capture
4) New code: use setPointerCapture(pointerId) instead (MDN advice)

⚠️
Learning only — not for production

MDN recommends against non-standard features in production. The setCapture / releaseCapture pair never had strong cross-browser support. Feature-detect, then teach the Pointer Events replacement.

Related tutorials: exitPointerLock(), querySelectorAll(), exitFullscreen().

Understanding document.releaseCapture()

An instance method on Document (MDN). It is not standardized.

  • Parameters — none (MDN).
  • Returnsundefined (MDN).
  • Effect — releases mouse capture if an element in this document currently has it (MDN).
  • Enable sideelement.setCapture() (MDN); that Element method is Deprecated & Non-standard.
  • Modern replacementElement.setPointerCapture() / releasePointerCapture() (MDN).
  • Spec — not part of any specification (MDN).

📝 Syntax

General form of Document.releaseCapture (MDN):

JavaScript
releaseCapture()

Parameters

None (MDN).

Return value

None (undefined) (MDN).

Enable capture (related API)

JavaScript
// Non-standard / Deprecated on Element (MDN)
element.setCapture();
// optional: element.setCapture(true); // retarget all events to this element

MDN-style pair

JavaScript
function mouseDown(e) {
  if (typeof e.target.setCapture === "function") {
    e.target.setCapture();
  }
  e.target.addEventListener("mousemove", mouseMoved);
}

function mouseUp(e) {
  if (typeof document.releaseCapture === "function") {
    document.releaseCapture();
  }
  e.target.removeEventListener("mousemove", mouseMoved);
}

⚡ Quick Reference

GoalCode / note
Feature-detecttypeof document.releaseCapture === "function"
Release capturedocument.releaseCapture()
Enable (legacy)element.setCapture() on mousedown (MDN)
Modern enableel.setPointerCapture(e.pointerId)
Modern releaseel.releasePointerCapture(e.pointerId)
MDN statusNon-standard — not in any specification

🔍 At a Glance

Four facts about document.releaseCapture().

Returns
undefined

MDN

Args
none

MDN

Pairs
setCapture

Element

Status
Non-std

MDN

📋 When capture starts and ends

SituationWhat happensTip
After setCapture()Mouse events retarget to that element until release (MDN)Usually call during mousedown
After releaseCapture()Normal targeting resumes (MDN)Call on mouseup or cancel
Mouse button releasedCapture often ends automatically in supporting enginesStill call release for clarity in demos
Unsupported browserMethod missingFeature-detect; use Pointer Events

Examples Gallery

Examples follow MDN Document: releaseCapture() and the related Element.setCapture() demo. Open try-it labs in a supporting engine (historically Firefox) to feel capture; elsewhere the labs show safe feature-detection messages.

📚 Getting Started

Detect support and understand the setCapture / releaseCapture pair.

Example 1 — Feature-detect first

Non-standard APIs must be checked before every call.

JavaScript
const hasRelease = typeof document.releaseCapture === "function";
const hasSet = typeof Element.prototype.setCapture === "function"
  || typeof HTMLElement.prototype.setCapture === "function";

console.log("releaseCapture:", hasRelease);
console.log("setCapture:", hasSet);

if (!hasRelease) {
  console.log("Prefer element.setPointerCapture / releasePointerCapture");
}
Try It Yourself

How It Works

Most Chromium / Safari builds report false. Treat that as expected.

Example 2 — setCapture then releaseCapture

Minimal pair: capture on press, release on button up.

JavaScript
const pad = document.getElementById("pad");
const log = document.getElementById("log");

pad.addEventListener("mousedown", (e) => {
  if (typeof pad.setCapture === "function") {
    pad.setCapture();
    log.textContent = "capture on";
  } else {
    log.textContent = "setCapture unsupported";
  }
});

pad.addEventListener("mouseup", () => {
  if (typeof document.releaseCapture === "function") {
    document.releaseCapture();
    log.textContent = "capture released";
  }
});
Try It Yourself

How It Works

MDN: enable with setCapture(), then document.releaseCapture() stops directing all mouse events to that element.

📈 Practical Patterns

MDN-style tracking, explicit mid-drag release, and the modern Pointer Events path.

Example 3 — MDN: track coordinates while captured

Adapted from the Element.setCapture example MDN links from releaseCapture.

JavaScript
function mouseMoved(e) {
  document.getElementById("output").textContent =
    "Position: " + e.clientX + ", " + e.clientY;
}

function mouseDown(e) {
  if (typeof e.target.setCapture === "function") {
    e.target.setCapture();
  }
  e.target.addEventListener("mousemove", mouseMoved);
}

function mouseUp(e) {
  if (typeof document.releaseCapture === "function") {
    document.releaseCapture();
  }
  e.target.removeEventListener("mousemove", mouseMoved);
}

const btn = document.getElementById("myButton");
if (btn && typeof btn.setCapture === "function") {
  btn.addEventListener("mousedown", mouseDown);
  btn.addEventListener("mouseup", mouseUp);
} else if (btn) {
  document.getElementById("output").textContent =
    "Sorry, there appears to be no setCapture support on this browser";
}
Try It Yourself

How It Works

Capture keeps mousemove on the element even if the pointer leaves its box; releaseCapture() (and removing the listener) ends the session.

Example 4 — Explicit release without waiting for mouseup

Call releaseCapture() from a cancel button mid-drag.

JavaScript
function startDrag(el) {
  if (typeof el.setCapture === "function") el.setCapture();
}

function cancelDrag() {
  if (typeof document.releaseCapture === "function") {
    document.releaseCapture();
    return "released";
  }
  return "releaseCapture unsupported";
}

// startDrag(pad); cancelDrag();
Try It Yourself

How It Works

MDN documents release as an explicit Document call — useful when UI cancels a gesture before the mouse button comes up.

Example 5 — Modern replacement: Pointer Events

MDN points you here for new code.

JavaScript
const pad = document.getElementById("pad");
const log = document.getElementById("log");

pad.addEventListener("pointerdown", (e) => {
  pad.setPointerCapture(e.pointerId);
  log.textContent = "pointer capture on " + e.pointerId;
});

pad.addEventListener("pointerup", (e) => {
  if (pad.hasPointerCapture(e.pointerId)) {
    pad.releasePointerCapture(e.pointerId);
  }
  log.textContent = "pointer capture released";
});

pad.addEventListener("pointermove", (e) => {
  if (!pad.hasPointerCapture(e.pointerId)) return;
  log.textContent = "move: " + e.clientX + ", " + e.clientY;
});
Try It Yourself

How It Works

Same drag UX idea as the legacy APIs, but standardized and available across modern browsers. This is the path to ship.

🚀 Common Use Cases

  • Legacy literacy — recognize Non-standard mouse capture APIs in old Gecko demos (MDN).
  • Ending a captured drag — call releaseCapture() when the gesture finishes or is canceled (MDN).
  • Pairing with setCapture — enable on mousedown, release on mouseup (MDN).
  • Not for production sites — MDN advises against non-standard features.
  • Migration teaching — contrast with setPointerCapture / releasePointerCapture.
  • Feature detection labs — show beginners how missing APIs look in DevTools.

🧠 How releaseCapture() Works

1

Element takes capture

element.setCapture() during mousedown (MDN).

Enable
2

Events retarget

Mouse events stay directed at that element while capture is on (MDN).

Route
3

Document releases

document.releaseCapture() clears capture for the document (MDN).

Release
4

Normal targeting resumes

For new apps, use Pointer Events capture APIs instead.

📝 Notes

  • MDN: marked Non-standard — not part of any specification.
  • Not marked Deprecated or Experimental on the Document page; still unsuitable for production dependency.
  • Related Element.setCapture() is Deprecated and Non-standard on MDN.
  • MDN examples for release live on the setCapture page.
  • Prefer setPointerCapture / releasePointerCapture (MDN warning).
  • Related: exitPointerLock(), querySelectorAll(), exitFullscreen().

Non-standard / Limited Browser Support

Document.releaseCapture() is Non-standard on MDN and is not part of any specification. Historical support was engine-specific (notably Gecko-oriented mouse capture). Logos use the shared browser-image-sprite.png sprite from this project.

Non-standard ยท Limited

Document.releaseCapture()

Release legacy mouse capture enabled by element.setCapture(). Feature-detect and prefer Pointer Events for production.

Limited Non-standard
Mozilla Firefox Legacy mouse capture
Limited
Google Chrome Use Pointer Events
No
Microsoft Edge Use Pointer Events
No
Apple Safari Use Pointer Events
No
Opera Use Pointer Events
No
Internet Explorer Related Element APIs
Legacy
releaseCapture() Narrow

Bottom line: Use only for legacy literacy. Ship Element.setPointerCapture() / releasePointerCapture() for real drag and slider UX.

Conclusion

document.releaseCapture() is a Non-standard way to end mouse capture that was started with element.setCapture(). Learn the MDN pair for literacy, then build new interactions with Pointer Events capture APIs.

Continue with replaceChildren(), exitPointerLock(), or the JavaScript hub.

💡 Best Practices

✅ Do

  • Feature-detect before calling
  • Prefer setPointerCapture / releasePointerCapture
  • Treat this as legacy / literacy material (MDN)
  • Pair release with the same gesture that called setCapture
  • Document Non-standard status in any legacy notes

❌ Don’t

  • Depend on it for production UX (MDN)
  • Assume Chrome / Safari implement it
  • Skip feature detection
  • Confuse Non-standard mouse capture with pointer lock
  • Ignore the Pointer Events migration path

Key Takeaways

Knowledge Unlocked

Five things to remember about releaseCapture()

Non-standard Document mouse-capture release.

5
Core concepts
🔄02

Args

none

MDN
🎯03

Pairs

setCapture

Element
04

Prefer

Pointer Events

modern
🛡05

Status

Non-std

MDN

❓ Frequently Asked Questions

MDN: Document.releaseCapture() releases mouse capture if it is currently enabled on an element within this document. After release, mouse events are no longer all directed to the capturing element.
MDN marks Document.releaseCapture() as Non-standard. It is not part of any specification. It is not marked Deprecated or Experimental on the Document page. Prefer Element.setPointerCapture() / releasePointerCapture() for new code.
MDN: enabling mouse capture is done by calling element.setCapture(). Document.releaseCapture() turns that capture off.
None (undefined) (MDN). There are no parameters.
MDN warns that the old setCapture / releaseCapture pair never had much cross-browser support. Use the Pointer Events API: element.setPointerCapture(pointerId) and element.releasePointerCapture(pointerId).
In supporting engines it is typically a safe no-op when capture is not active. Always feature-detect first because most modern browsers do not implement Document.releaseCapture().
Did you know?

MDN’s Document page for releaseCapture() does not include its own live demo — it points you to the Element.setCapture() examples instead, because capture must be enabled before it can be released.

Next: replaceChildren()

Learn how Document.replaceChildren() empties or swaps Document children with the ParentNode API.

replaceChildren() →

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.

6 people found this page helpful