JavaScript Element setCapture() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Method

Definition

Call Element.setCapture() during a mousedown handler to retarget mouse events to that element until the button is released or document.releaseCapture() runs (MDN). Prefer modern setPointerCapture().

Pass the required arguments shown below. Check return values and browser support before you rely on the result.

Syntax

Call el.setCapture. Start with this line.

JavaScript
el.setCapture(retargetToElement?)
CallWhat it does
el.setCapture(retargetToElement?)Primary signature.
el.setCapture(...)Call with the arguments your case needs.

Built into the browser. Call setCapture(...) on an Element — no import required.

Library declarations
JavaScript
el.setCapture(retargetToElement?)

Parameters

ParameterDescription
retargetToElementOptional. true = this element only; false = include descendants
Call siteRequired. During mousedown handling (MDN)

Return Value

Return ValueDescription
*Always undefined

JavaScript Examples

Example 1 — Feature Detect

MDN-style check before touching the legacy API.

JavaScript
const btn = document.getElementById("myButton");

if (typeof btn.setCapture === "function") {
  console.log("Legacy setCapture is present");
} else {
  console.log("Use setPointerCapture instead");
}
Try It Yourself

How It Works

  1. Detect. Most browsers omit setCapture.
  2. Branch. Don’t call a missing method.
  3. Migrate. Point new code at Pointer Events.
  4. Status. Deprecated · Non-standard (MDN).

Example 2 — Legacy mousedown Pattern

MDN Gecko pattern — for understanding old code only.

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

function mouseUp(e) {
  e.target.removeEventListener("mousemove", mouseMoved);
}

function mouseMoved(e) {
  console.log(e.clientX, e.clientY);
}

const btn = document.getElementById("myButton");
btn.addEventListener("mousedown", mouseDown);
btn.addEventListener("mouseup", mouseUp);
Try It Yourself

How It Works

  1. mousedown. MDN: call capture during this handler.
  2. setCapture. Retargets mouse events to the element.
  3. mousemove. Tracks position while the button is held.
  4. mouseup. Capture ends; remove the move listener.

Example 3 — Prefer setPointerCapture

MDN’s recommended replacement from the Pointer Events API.

JavaScript
const btn = document.getElementById("myButton");

btn.addEventListener("pointerdown", (e) => {
  btn.setPointerCapture(e.pointerId);
});

btn.addEventListener("pointermove", (e) => {
  if (!btn.hasPointerCapture(e.pointerId)) return;
  console.log(e.clientX, e.clientY);
});

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

How It Works

  1. pointerdown. Capture that pointer Id on the element.
  2. pointermove. Events keep targeting the element while captured.
  3. pointerup. Release when done.
  4. Portable. Works across modern browsers — unlike setCapture.

Browser Support

Element.setCapture() is Deprecated and Non-standard on MDN — not part of any specification, and never had broad cross-browser support. Prefer setPointerCapture().

✓ Deprecated · Non-standard

Element.setCapture()

Legacy Gecko mouse capture during mousedown. Use Pointer Events setPointerCapture() for new code.

Legacy Avoid in new code
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Android WebView Supported · Modern WebView
Full support
setCapture() Deprecated

Bottom line: Do not ship setCapture() in production. Feature-detect only for legacy maintenance; migrate to setPointerCapture().

Frequently Asked Questions

During mousedown handling, it retargets mouse events to this element until the mouse button is released or document.releaseCapture() is called (MDN).
MDN marks Element.setCapture() as Deprecated and Non-standard. It is not Experimental and is not part of any specification — do not use it in new projects.
undefined. There is no return value (MDN).
Optional boolean. true targets all events directly at this element; false allows events on descendants too (MDN).
MDN recommends Element.setPointerCapture() from the Pointer Events API for modern pointer capture / drag workflows.
No practical cross-browser support. MDN notes it never had much cross-browser support (legacy Gecko).

Prefer: setPointerCapture()

Learn the modern Pointer Events capture API for drag and tracking UIs.

setPointerCapture() →

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.

11 people found this page helpful