JavaScript element.setPointerCapture() Method

You are Here:

JavaScript element.setPointerCapture() Method

The element.setPointerCapture() method allows events for a particular pointer event to be re-targeted to a particular element instead of the normal target at a pointer's location.


HTML Online Editor
<!DOCTYPE html> <html> <body> <button onpointerdown="pointDown(event)" onpointerup="pointerUp(event);">Press Me</button> <p id="point"></p> <script> var x = document.getElementById("point"); var elem = document.getElementsByTagName("button")[0]; function pointDown(e){ elem.setPointerCapture(e.pointerId); check(e); } function pointerUp(e){ elem.releasePointerCapture(e.pointerId); check(e); } function check(e){ if(elem.hasPointerCapture(e.pointerId)) x.innerHTML = "Your mouse pointer is captured"; else x.innerHTML = "Your mouse pointer is released"; } </script> </body> </html>



Parameter Values

pointerIdRequiredThe pointerId of a PointerEvent object.


Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in JavaScript.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author