Element: mousedown event
UI Events
UI Events
The mousedown event is fired at an Element when a pointing device button is pressed while the pointer is inside the element.
This differs from the click event in that click is fired after a full click action occurs; that is, the mouse button is pressed and released while the pointer remains inside the same element. mousedown is fired the moment the button is initially pressed.
This behavior is different from pointerdown 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.
Syntax
Use the event name in addEventListener():
addEventListener("mousedown", (event) => { })
Alternatively, assign to the event handler property of the interface:
onmousedown = (event) => { }
Event type
A MouseEvent. Inherits from UIEvent and Event.
MouseEvent
Examples
See mousemove event for example code.
Specifications
Browser compatibility
See also
- Learn: Introduction to events
- mouseup
- mousemove
- click
- dblclick
- mouseover
- mouseout
- mouseenter
- mouseleave
- contextmenu
- pointerdown