Element: pointerdown event
Pointer Events
Pointer Events
The pointerdown event is fired when a pointer becomes active. For mouse, it is fired when the device transitions from no buttons pressed to at least one button pressed. For touch, it is fired when physical contact is made with the digitizer. For pen, it is fired when the stylus makes physical contact with the digitizer.
This behavior is different from mousedown events. When using a physical mouse, mousedown events fire whenever any button on a mouse is pressed down. pointerdown events fire only upon the first button press; subsequent button presses don't fire pointerdown events.
[!NOTE] For touchscreen browsers that allow direct manipulation, a
pointerdownevent triggers implicit pointer capture, which causes the target to capture all subsequent pointer events as if they were occurring over the capturing target. Accordingly,pointerover,pointerenter,pointerleave, andpointeroutwill not fire as long as this capture is set. The capture can be released manually by calling element.releasePointerCapture on the target element, or it will be implicitly released after apointeruporpointercancelevent.
Syntax
Use the event name in addEventListener():
addEventListener("pointerdown", (event) => { })
Alternatively, assign to the event handler property of the interface:
onpointerdown = (event) => { }
Event type
A PointerEvent. Inherits from Event.
PointerEvent
Examples
Using addEventListener():
const para = document.querySelector("p");
para.addEventListener("pointerdown", (event) => {
console.log("Pointer down event");
});
Using the onpointerdown event handler property (but note that this replaces other event listeners added using onpointerdown, if any):
const para = document.querySelector("p");
para.onpointerdown = (event) => {
console.log("Pointer down event");
};
Specifications
Browser compatibility
See also
- Related events
- gotpointercapture
- lostpointercapture
- pointerover
- pointerenter
- pointermove
- pointerup
- pointercancel
- pointerout
- pointerleave
- pointerrawupdate
- mousedown