MouseEvent: MouseEvent() constructor
====================================

The **`MouseEvent()`** constructor creates a new `MouseEvent` object.

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`, or `mouseup`.


`options` Optional

An object that, *in addition of the properties defined in `UIEvent()`*, can have the following properties:

`screenX` Optional

 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.


`screenY` Optional

 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.


`clientX` Optional

 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.


`clientY` Optional

 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.


`ctrlKey` Optional

A boolean value indicating if the `ctrl` key was simultaneously pressed. It defaults to `false`.

`shiftKey` Optional

A boolean value indicating if the `shift` key was simultaneously pressed. It defaults to `false`.

`altKey` Optional

A boolean value indicating if the `alt` key was simultaneously pressed. It defaults to `false`.

`metaKey` Optional

A boolean value indicating if the `meta` key was simultaneously pressed. It defaults to `false`.

`button` Optional

A number, defaulting to `0`, that describes which button is pressed during events related to the press or release of a button:

| Value | Meaning |
| --- | --- |
| `0` | Main button pressed (usually the left button) or un-initialized |
| `1` | Auxiliary button pressed (usually the middle button) |
| `2` | Secondary button pressed (usually the right button) |

`buttons` Optional

A number, defaulting to `0`, that describes which buttons are pressed when the event is launched:

| Bit-field value | Meaning |
| --- | --- |
| `0` | No button pressed |
| `1` | Main button pressed (usually the left button) |
| `2` | Secondary button pressed (usually the right button) |
| `4` | Auxiliary button pressed (usually the middle button) |

`relatedTarget` Optional

 An `EventTarget`, defaulting to `null` that is the element just left
 (in case of a `mouseenter` or `mouseover`)
 or is entering (in case of a `mouseout` or `mouseleave`).


`region` 
Non-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 the `null` value.



 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
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `MouseEvent`, the interface of the objects it constructs.