The hasPointerCapture()
method of the Element
interface checks whether the element on which it is invoked has pointer capture for the pointer identified by the given pointer ID.
On this page
Element: hasPointerCapture() method
Syntax
js
hasPointerCapture(pointerId)
Parameters
-
pointerId
-
The
pointerId
of aPointerEvent
object.
Return value
A boolean value — true
if the element does have pointer capture, false
if it doesn't.
Examples
html
<html lang="en">
<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 |
---|
Pointer Events # dom-element-haspointercapture |
Browser compatibility
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
hasPointerCapture |
55 | 79 | 59 | No | 42 | 13 | 55 | 55 | 79 | 42 | 13 | 6.0 |
See also
© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Element/hasPointerCapture