W3cubDocs

/DOM

element.hasPointerCapture

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

Syntax

targetElement.hasPointerCapture(pointerId);

Arguments

pointerId
The identifier for a pointer event.

Return value

A boolean value — true if the element does have ponter 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 me ... </div>
  </body>
</html>

Specifications

Browser compatibility

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.

No compatibility data found. Please contribute data for "api.Element.hasPointerCapture" (depth: 1) to the MDN compatibility data repository.

See also

© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/element/hasPointerCapture