Web/API/Element/hasPointerCapture

From Get docs


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 2The definition of 'hasPointerCapture()' in that specification. Recommendation  

Browser compatibility

Update compatibility data on GitHub

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
hasPointerCapture Chrome

Full support 55

Edge

Full support 79

Firefox 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

No support No

Opera

Full support 42

Safari

Full support 13

WebView Android

Full support 55

Chrome Android

Full support 55

Firefox 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 42

Safari iOS

Full support 13

Samsung Internet Android

Full support 6.0

Legend

Full support  
Full support
No support  
No support
User must explicitly enable this feature.'
User must explicitly enable this feature.


See also