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
pointerIdof aPointerEventobject.
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
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.
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
hasPointerCapture | Chrome Full support 55 | Edge Full support ≤79 | Firefox
Full support
59
| IE ? | Opera Full support 42 | Safari Full support 13 | WebView Android Full support 55 | Chrome Android Full support 55 | Firefox Android
No support
No
| 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
- Compatibility unknown
- Compatibility unknown
- User must explicitly enable this feature.
- User must explicitly enable this feature.
