Element.setCapture() is a deprecated, non-standard instance method that retargets mouse events to an element after mousedown. Learn MDN’s coordinate-tracking demo, the retargetToElement flag, document.releaseCapture() cleanup, feature detection, and why setPointerCapture() replaced it—plus five try-it labs aligned with MDN.
01
Kind
Instance method
02
Trigger
On mousedown
03
Returns
undefined
04
Status
Deprecated · Non-standard
05
Modern alt
setPointerCapture
06
Release
mouseup / releaseCapture
Fundamentals
Introduction
When a user presses the mouse button on an element and drags, the pointer can leave that element’s bounds. Normally, mousemove events would stop targeting the original element. Legacy Gecko code used setCapture() to keep receiving mouse events until the button was released.
Call element.setCapture(retargetToElement) during a mousedown handler (MDN). Capture ends when the user releases the mouse button or when document.releaseCapture() is called.
💡
Modern replacement (MDN)
MDN warns this API never had much cross-browser support. For new code, use element.setPointerCapture(pointerId) from the Pointer Events API instead. It works across modern browsers for mouse, pen, and touch.
Calling el.setCapture() during mousedown redirects subsequent mouse events to el until capture is released. It was introduced for Gecko 2.0 mouse-capture scenarios (MDN).
It is an instance method on Element.
retargetToElement — if true, all events target this element; if false, descendants may also receive events (MDN).
Returns undefined.
Deprecated and non-standard on MDN — not part of any specification.
Ends on mouse button release or document.releaseCapture() (MDN).
Modern alternative: setPointerCapture() / releasePointerCapture().
Foundation
📝 Syntax
General form of Element.setCapture (MDN):
JavaScript
setCapture(retargetToElement)
Parameters
Parameter
Type
Description
retargetToElement
boolean
If true, all events target this element; if false, descendants may also receive events (MDN).
Return value
Type
Description
undefined
No return value (MDN).
Notes
Call during mousedown handling (MDN).
Capture ends on mouse button release or document.releaseCapture() (MDN).
The element may not scroll fully to top/bottom depending on layout (MDN).
Common patterns
JavaScript
const btn = document.getElementById("myButton");
function onMouseDown(e) {
if (!e.target.setCapture) return;
e.target.setCapture();
e.target.addEventListener("mousemove", onMouseMove);
}
function onMouseUp(e) {
e.target.removeEventListener("mousemove", onMouseMove);
}
function onMouseMove(e) {
console.log(e.clientX, e.clientY);
}
if (btn.setCapture) {
btn.addEventListener("mousedown", onMouseDown);
btn.addEventListener("mouseup", onMouseUp);
}
Cheat Sheet
⚡ Quick Reference
Goal
Code
Start mouse capture
el.setCapture() on mousedown
Retarget only to element
el.setCapture(true)
Allow descendant targets
el.setCapture(false)
Release programmatically
document.releaseCapture()
Feature detect
if (el.setCapture) { ... }
MDN status
Deprecated · Non-standard
Snapshot
🔍 At a Glance
Four facts to remember about Element.setCapture().
Returns
undefined
No value
Status
deprecated
Non-standard
When
mousedown
Start capture
Modern
setPointerCapture
Use instead
Compare
📋 setCapture() vs setPointerCapture()
setCapture(retarget)
setPointerCapture(id)
addEventListener on document
Status
Deprecated, non-standard
Standard Pointer Events
Standard DOM Events
Input types
Mouse only (legacy)
Mouse, pen, touch
Any event type
Trigger
On mousedown (MDN)
On pointerdown
Manual wiring
Release
mouseup / releaseCapture
pointerup / releasePointerCapture
removeEventListener
Best for
Legacy Gecko maintenance
New drag/slider UIs
Fallback patterns
Hands-On
Examples Gallery
Examples follow MDN Element.setCapture() patterns. Use View Output or Try It Yourself for each case. Note: this API may be unavailable in your browser—examples include feature detection.
📚 Getting Started
MDN’s mouse-coordinate demo and the retargetToElement flag.
Example 1 — Track Mouse Coordinates (MDN)
On mousedown, call setCapture() and draw coordinates while the button is held.
JavaScript
function mouseDown(e) {
e.target.setCapture();
e.target.addEventListener("mousemove", mouseMoved);
}
function mouseUp(e) {
e.target.removeEventListener("mousemove", mouseMoved);
}
function mouseMoved(e) {
const output = document.getElementById("output");
output.textContent = `Position: ${e.clientX}, ${e.clientY}`;
}
const btn = document.getElementById("myButton");
if (btn.setCapture) {
btn.addEventListener("mousedown", mouseDown);
btn.addEventListener("mouseup", mouseUp);
}
Element.setCapture() is deprecated and non-standard (MDN). It was a legacy Gecko mouse-capture API with little cross-browser support. Logos use the shared browser-image-sprite.png sprite from this project.
✓ Deprecated · Non-standard
Element.setCapture()
Legacy Gecko mouse capture — use setPointerCapture() for new drag and pointer-tracking UIs.
LegacyNot for new apps
Google ChromeNot supported
No
Microsoft EdgeNot supported
No
Mozilla FirefoxLegacy Gecko API; may be absent in modern builds
Legacy
Apple SafariNot supported
No
OperaNot supported
No
Internet ExplorerNot supported
No
setCapture()Deprecated
Bottom line: Feature-detect with if (el.setCapture) in legacy code only. For new projects, use setPointerCapture() from the Pointer Events API.
Wrap Up
Conclusion
Element.setCapture() was a legacy way to keep receiving mouse events after mousedown. MDN marks it deprecated and non-standard, with limited browser support. Returns undefined.
Feature-detect with if (el.setCapture) in legacy code
Remove mousemove listeners on mouseup
Call document.releaseCapture() when canceling early
Document Gecko-only behavior for maintainers
❌ Don’t
Use setCapture() in new cross-browser projects
Assume capture works in Chrome, Safari, or Edge
Forget to clean up listeners after capture ends
Expect a useful return value (it is undefined)
Confuse with setPointerCapture() or event bubbling
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about Element.setCapture()
Legacy mouse capture — deprecated, use Pointer Events instead.
5
Core concepts
📝01
Returns
undefined
API
📄02
Trigger
mousedown
Event
⚠️03
Status
deprecated
Legacy
🖱️04
Modern
setPointerCapture
Prefer
✅05
Release
mouseup
End
❓ Frequently Asked Questions
During mousedown handling, it retargets all mouse events to the 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, but it is not part of any specification and should not be used in new production code.
undefined. There is no return value (MDN).
If true, all events target this element directly. If false, events can also fire on descendants of this element (MDN).
MDN recommends element.setPointerCapture() from the Pointer Events API for modern drag-and-track-pointer workflows.
No practical cross-browser support. MDN notes it never had much cross-browser support and was primarily a legacy Gecko API.
Did you know?
MDN introduced setCapture() for Gecko 2.0 mouse capture, but the web platform moved on to setPointerCapture()—which handles mouse, pen, and touch with standard cross-browser support.