Element.hasPointerCapture()

The hasPointerCapture() method of the Element interface sets whether the element on which it is invoked has pointer capture for the pointer identified by the given pointer ID.

Syntax

targetElement.hasPointerCapture(pointerId);

Parameters

pointerId
The pointerId of a PointerEvent object.

Return value

A Boolean value — true if the element does have pointer capture, false if it doesn't.

Examples

<html>
  <script>
    function downHandler(ev) {
      const el = document.getElementById("target");
      // Element 'target' will receive/capture further events
      el.setPointerCapture(ev.pointerId);

      /* ... */

      // Check whether element still has pointer capture
      let pointerCap = el.hasPointerCapture(ev.pointerId);
      if(pointerCap) {
        // We've still got pointer capture
      } else {
        // oops, we've lost pointer capture!
      }
    }

    function init() {
      const el = document.getElementById("target");
      el.onpointerdown = downHandler;
    }
  </script>
  <body onload="init();">
    <div id="target">Touch this element with a pointer.</div>
  </body>
</html>

Specifications

Specification Status Comment
Pointer Events – Level 2
The definition of 'hasPointerCapture()' in that specification.
Recommendation

Browser compatibility

DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
hasPointerCaptureChrome Full support 55Edge Full support ≤79Firefox Full support 59
Full support 59
Full support 41
Disabled
Disabled From version 41: this feature is behind the dom.w3c_pointer_events.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
IE ? Opera Full support 42Safari Full support 13WebView Android Full support 55Chrome Android Full support 55Firefox Android No support No
No support No
Full support 41
Disabled
Disabled From version 41: this feature is behind the dom.w3c_pointer_events.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
Opera Android Full support 42Safari iOS Full support 13Samsung Internet Android Full support 6.0

Legend

Full support
Full support
No support
No support
Compatibility unknown
Compatibility unknown
User must explicitly enable this feature.
User must explicitly enable this feature.

See also