<div id="target">Touch this element with a pointer.</div>Element: hasPointerCapture() method / notebook
Element: hasPointerCapture() method
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
const el = document.getElementById("target");
el.addEventListener("pointerdown", (ev) => {
// Element 'target' will receive/capture further events
el.setPointerCapture(ev.pointerId);
// …
// Check whether element still has pointer capture
const pointerCap = el.hasPointerCapture(ev.pointerId);
if (pointerCap) {
// We've still got pointer capture
} else {
// oops, we've lost pointer capture!
}
});