JavaScript Element hasPointerCapture() Method

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

What You’ll Learn

Element.hasPointerCapture() is an instance method that returns true or false depending on whether this element currently holds pointer capture for a given pointerId. Learn the MDN pointerdown pattern with setPointerCapture() and releasePointerCapture(), drag-handler guards, and five try-it labs aligned with MDN.

01

Kind

Instance method

02

Returns

boolean

03

Arg

pointerId

04

Capture

true / false

05

Events

Pointer

06

Status

Baseline widely

Introduction

When a user presses a mouse button, touches a screen, or uses a pen, the browser fires Pointer Events with a unique pointerId. Normally, events target the element under the pointer. With setPointerCapture(pointerId), an element can keep receiving pointer events even when the pointer moves outside it — useful for dragging sliders, drawing pads, and custom controls.

hasPointerCapture(pointerId) lets you check whether your element currently owns that pointer. MDN: it returns whether the element has pointer capture for the pointer identified by the given pointer ID.

💡
Beginner tip

Call hasPointerCapture inside pointerdown, pointermove, or pointerup handlers where event.pointerId is valid. Pass that same ID to the method.

This page is part of JavaScript Element. Pair this method with setPointerCapture() and releasePointerCapture() on MDN.

Understanding the hasPointerCapture() Method

Calling el.hasPointerCapture(pointerId) asks: does this element currently hold capture for that pointer?

  • It is an instance method on Element.
  • Takes one parameter: pointerId from a PointerEvent (MDN).
  • Returns true when this element has capture for that pointer.
  • Returns false when it does not (or capture was released).
  • Does not set or release capture — only checks state.
  • Commonly used after setPointerCapture() or in drag handlers.
  • Part of the Pointer Events API (Baseline since July 2020).

📝 Syntax

General form of Element.hasPointerCapture (MDN):

JavaScript
hasPointerCapture(pointerId)

Parameters

pointerId — The pointerId of a PointerEvent object (MDN).

Return value

A boolean: true if the element has pointer capture for that pointer, false if it does not (MDN).

Common patterns

JavaScript
// MDN example
const el = document.getElementById("target");
el.addEventListener("pointerdown", (ev) => {
  el.setPointerCapture(ev.pointerId);

  const pointerCap = el.hasPointerCapture(ev.pointerId);
  if (pointerCap) {
    // Still have pointer capture
  }
});

// Guard in pointermove (drag)
box.addEventListener("pointermove", (ev) => {
  if (!box.hasPointerCapture(ev.pointerId)) return;
  // handle drag
});

// After release
box.releasePointerCapture(ev.pointerId);
console.log(box.hasPointerCapture(ev.pointerId)); // false

⚡ Quick Reference

GoalCode
Has capture?el.hasPointerCapture(id)
Request captureel.setPointerCapture(id)
Release captureel.releasePointerCapture(id)
Pointer IDevent.pointerId
No capturefalse
MDN statusBaseline Widely available (since July 2020)

🔍 At a Glance

Four facts to remember about Element.hasPointerCapture().

Returns
boolean

true / false

Baseline
widely

Since Jul 2020

Arg
pointerId

From event

Pair with
setCap

Capture API

📋 Pointer capture APIs

hasPointerCapture()setPointerCapture()releasePointerCapture()
Returnstrue / falseundefinedundefined
ActionCheck capture stateRequest captureRelease capture
ParameterspointerIdpointerIdpointerId
Typical useGuard in handlersStart drag / sliderEnd drag / cleanup
Best forConfirm ownershipKeep receiving eventsGive capture back

Examples Gallery

Examples follow MDN Element.hasPointerCapture() patterns. Use View Output or Try It Yourself for each case.

📚 Getting Started

MDN pointerdown pattern and capture checks.

Example 1 — MDN Basic Check

After setPointerCapture, verify capture is active (MDN).

JavaScript
const el = document.getElementById("target");

el.addEventListener("pointerdown", (ev) => {
  el.setPointerCapture(ev.pointerId);

  const pointerCap = el.hasPointerCapture(ev.pointerId);
  if (pointerCap) {
    console.log("capture active");
  } else {
    console.log("capture lost");
  }
});
Try It Yourself

How It Works

Inside pointerdown, call setPointerCapture(ev.pointerId), then hasPointerCapture(ev.pointerId) should return true (MDN).

Example 2 — Before vs After setPointerCapture

Compare capture state before and after requesting capture.

JavaScript
const box = document.getElementById("box");

box.addEventListener("pointerdown", (ev) => {
  console.log(box.hasPointerCapture(ev.pointerId)); // false
  box.setPointerCapture(ev.pointerId);
  console.log(box.hasPointerCapture(ev.pointerId)); // true
});
Try It Yourself

How It Works

Before capture is set, the method returns false. Immediately after setPointerCapture, the same element and pointerId return true.

📈 Practical Patterns

Release checks, other elements, and drag guards.

Example 3 — After releasePointerCapture

Confirm capture is gone after explicitly releasing it.

JavaScript
const slider = document.getElementById("slider");

slider.addEventListener("pointerdown", (ev) => {
  slider.setPointerCapture(ev.pointerId);
  slider.releasePointerCapture(ev.pointerId);
  console.log(slider.hasPointerCapture(ev.pointerId)); // false
});
Try It Yourself

How It Works

releasePointerCapture(pointerId) ends capture. A follow-up hasPointerCapture call returns false for that pointer.

Example 4 — Wrong Element Returns false

Only the element that holds capture returns true.

JavaScript
const box = document.getElementById("box");
const other = document.getElementById("other");

box.addEventListener("pointerdown", (ev) => {
  box.setPointerCapture(ev.pointerId);
  console.log(box.hasPointerCapture(ev.pointerId));   // true
  console.log(other.hasPointerCapture(ev.pointerId)); // false
});
Try It Yourself

How It Works

Pointer capture belongs to one element at a time per pointer. Checking a different element with the same pointerId returns false.

Example 5 — Guard in pointermove

Only handle drag logic when this element still owns the pointer.

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

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

handle.addEventListener("pointermove", (ev) => {
  if (!handle.hasPointerCapture(ev.pointerId)) return;
  console.log("dragging at", ev.clientX, ev.clientY);
});
Try It Yourself

How It Works

A common drag pattern: capture on pointerdown, then guard pointermove with hasPointerCapture so stray events are ignored.

🚀 Common Use Cases

  • Verifying capture after setPointerCapture() (MDN pattern).
  • Guarding pointermove handlers during custom drag UIs.
  • Confirming cleanup after releasePointerCapture().
  • Custom sliders, knobs, and drawing pads with pointer events.
  • Debugging which element owns a pointer during interaction.
  • Defensive checks before updating UI state on pointerup.

🧠 How hasPointerCapture() Checks Capture

1

Pass pointerId

element.hasPointerCapture(event.pointerId)

Args
2

Lookup capture target

Browser checks whether this element holds capture for that pointer (MDN).

Lookup
3

Return boolean

true if this element has capture, false if not.

Result
4

Branch or continue drag

Use in conditionals; pair with setPointerCapture() and releasePointerCapture() to manage the pointer lifecycle.

📝 Notes

  • Not Deprecated, Experimental, or Non-standard on MDN (Baseline Widely available, July 2020).
  • Requires a valid pointerId from a PointerEvent (MDN).
  • Only checks state — use setPointerCapture() to request capture.
  • Returns false on elements that never captured that pointer.
  • Capture may end on pointerup, pointercancel, or releasePointerCapture().
  • Related: hasAttributes(), getBoundingClientRect(), setPointerCapture(), JavaScript hub.

Browser Support

Element.hasPointerCapture() is Baseline Widely available (MDN: across browsers since July 2020). Logos use the shared browser-image-sprite.png sprite from this project.

Baseline Widely available

Element.hasPointerCapture()

Check whether an element has pointer capture for a pointerId — returns true or false.

Baseline Widely available
Google Chrome Supported · Desktop & Mobile
Yes
Microsoft Edge Supported · Chromium
Yes
Mozilla Firefox Supported · Desktop & Mobile
Yes
Apple Safari Supported · macOS & iOS
Yes
Opera Supported · Modern versions
Yes
Internet Explorer Not supported
No
hasPointerCapture() Excellent

Bottom line: Use hasPointerCapture() to confirm capture before handling pointermove or pointerup. Request capture with setPointerCapture() first.

Conclusion

Element.hasPointerCapture() checks whether an element currently holds pointer capture for a given pointerId. It is the read-only companion to setPointerCapture() and releasePointerCapture().

Continue with hasAttributes(), getBoundingClientRect(), shadowRoot, or the JavaScript hub.

💡 Best Practices

✅ Do

  • Pass event.pointerId from the active PointerEvent
  • Call setPointerCapture() on pointerdown for drags
  • Guard pointermove with hasPointerCapture()
  • Release capture on pointerup when done
  • Use Pointer Events for mouse, touch, and pen input

❌ Don’t

  • Call without a real pointerId from an event
  • Confuse with setting capture (use setPointerCapture)
  • Assume capture lasts forever without release
  • Check capture on the wrong element
  • Rely on mouse-only events for cross-device UIs

Key Takeaways

Knowledge Unlocked

Five things to remember about Element.hasPointerCapture()

Pointer capture state checks.

5
Core concepts
📄 02

Arg

pointerId

Event
👆 03

Capture

set/release

Pair
04

Drag

guard

move
05

API

Pointer

Events

❓ Frequently Asked Questions

It returns a boolean indicating whether the element has pointer capture for the pointer identified by the given pointer ID (MDN).
No. MDN marks Element.hasPointerCapture() as Baseline Widely available (across browsers since July 2020). It is not Deprecated, Experimental, or Non-standard.
The pointerId from a PointerEvent object (for example event.pointerId from pointerdown, pointermove, or pointerup).
When the element currently holds pointer capture for that pointerId — typically after setPointerCapture(pointerId) and before releasePointerCapture(pointerId) or pointerup.
setPointerCapture() requests capture for a pointer. hasPointerCapture() only checks whether capture is already active on this element.
Useful in drag handlers and custom sliders: confirm your element still owns the pointer before handling pointermove or pointerup events (MDN).
Did you know?

MDN: after setPointerCapture(pointerId), call hasPointerCapture(pointerId) to confirm your element still owns the pointer before handling follow-up pointer events.

Next: setPointerCapture()

Learn how to request pointer capture for drag and slider interactions.

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.

8 people found this page helpful