files/en-us/web/api/mouseevent/initmouseevent/index.md
{{APIRef("Pointer Events")}}{{deprecated_header}}
The MouseEvent.initMouseEvent() method initializes the
value of a mouse event once it's been created (normally using the {{domxref("Document.createEvent()")}} method).
[!WARNING] Do not use this method anymore as it is deprecated.
Instead use specific event constructors, like {{domxref("MouseEvent.MouseEvent", "MouseEvent()")}}. The section on Creating and dispatching events gives more information about the way to use these.
Events initialized in this way must have been created with the {{domxref("Document.createEvent()") }} method. This method must be called to set the event before it is dispatched, using {{ domxref("EventTarget.dispatchEvent()") }}.
initMouseEvent(type, canBubble, cancelable, view,
detail, screenX, screenY, clientX, clientY,
ctrlKey, altKey, shiftKey, metaKey,
button, relatedTarget)
type
click, mousedown,
mouseup, mouseover, mousemove,
mouseout.canBubble
cancelable
view
detail
screenX
screenY
clientX
clientY
ctrlKey
altKey
shiftKey
metaKey
button
relatedTarget
mouseover and mouseout). In
other cases, pass null.None ({{jsxref("undefined")}}).
const event = document.createEvent("MouseEvents");
event.initMouseEvent(
"click",
true,
true,
window,
0,
0,
0,
80,
20,
false,
false,
false,
false,
0,
null,
);
document.body.dispatchEvent(event);
{{Specifications}}
{{Compat}}