The MouseEvent() constructor creates a new MouseEvent object.
On this page
MouseEvent: MouseEvent() constructor
Syntax
js
new MouseEvent(type)
new MouseEvent(type, options)
Parameters
-
type -
A string with the name of the event. It is case-sensitive and browsers set it to
dblclick,mousedown,mouseenter,mouseleave,mousemove,mouseout,mouseover, ormouseup. optionsOptional-
An object that, in addition of the properties defined in
UIEvent(), can have the following properties:screenXOptional-
A number, defaulting to
0, that is the horizontal position of the mouse event on the user's screen; setting this value doesn't move the mouse pointer. screenYOptional-
A number, defaulting to
0, that is the vertical position of the mouse event on the user's screen; setting this value doesn't move the mouse pointer. clientXOptional-
A number, defaulting to
0, that is the horizontal position of the mouse event on the client window of user's screen; setting this value doesn't move the mouse pointer. clientYOptional-
A number, defaulting to
0, that is the vertical position of the mouse event on the client window of the user's screen; setting this value doesn't move the mouse pointer. ctrlKeyOptional-
A boolean value indicating if the ctrl key was simultaneously pressed. It defaults to
false. shiftKeyOptional-
A boolean value indicating if the shift key was simultaneously pressed. It defaults to
false. altKeyOptional-
A boolean value indicating if the alt key was simultaneously pressed. It defaults to
false. metaKeyOptional-
A boolean value indicating if the meta key was simultaneously pressed. It defaults to
false. -
A number, defaulting to
0, that describes which button is pressed during events related to the press or release of a button:Value Meaning 0Main button pressed (usually the left button) or un-initialized 1Auxiliary button pressed (usually the middle button) 2Secondary button pressed (usually the right button) -
A number, defaulting to
0, that describes which buttons are pressed when the event is launched:Bit-field value Meaning 0No button pressed 1Main button pressed (usually the left button) 2Secondary button pressed (usually the right button) 4Auxiliary button pressed (usually the middle button) -
An
EventTarget, defaulting tonullthat is the element just left (in case of amouseenterormouseover) or is entering (in case of amouseoutormouseleave). regionNon-standard Optional-
A string, defaulting to
null, that is the ID of the hit region affected by the event. The absence of any affected hit region is represented with thenullvalue.
In some implementations, passing anything other than a number for the screen and client fields will throw a
TypeError.
Specifications
| Specification |
|---|
| UI Events # dom-mouseevent-mouseevent |
Browser compatibility
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
MouseEvent |
26 | 12 | 11 | No | 15 | 7 | 4.4 | 26 | 14 | 14 | 7 | 1.5 |
See also
MouseEvent, the interface of the objects it constructs.
© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent