DOM MouseEvent Interface
MouseEvent describes events caused by a mouse or other pointing device, such as click and mousemove, including the pointer position and which button was pressed.
Description
The MouseEvent interface represents events that occur because of the user interacting with a pointing device, such as click, dblclick, mousedown, mouseup, mousemove, mouseenter and contextmenu. It provides the pointer's position (clientX, pageX, offsetX and others), which button was used, and whether modifier keys such as Shift were held (shiftKey, ctrlKey, altKey, metaKey).
PointerEvent extends it to cover touch and pen input too, and is the better choice for new code that should work on every device.
The relatedTarget property is useful for mouseover, mouseout, mouseenter and mouseleave, where it identifies the element the pointer came from or moved to. Note that mouseenter and mouseleave don't bubble, while mouseover and mouseout do. On touch screens, browsers also send compatibility mouse events after a tap, so a single tap can trigger both touch and mouse handlers unless you use pointer events.
Inheritance
MouseEvent inherits properties and methods from Event.
Properties
| Name | Description |
|---|---|
MouseEvent.button | The button property tells you which mouse button was pressed or released: 0 for the main button, 1 for the middle and 2 for the secondary button. |
MouseEvent.clientX | The clientX and clientY properties give the position of the mouse pointer when the event happened, relative to the viewport. |
Example
Browser Support
The following information will show you the current browser support for the MouseEvent interface. Hover over a browser icon to see the version that first introduced support for this interface.
Desktop





Tablets & Mobile





