HTM DOM Document createEvent()
Example
Simulate a mouseover event:
const ev = document.createEvent("MouseEvent");
ev.initMouseEvent("mouseover", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
document.getElementById("myDiv").dispatchEvent(ev);
Try it Yourself »
Definition and Usage
The createEvent() method creates an event
object.
The event must be of a legal event type, and must be initialized (dipatched) before use.
Syntax
document.createEvent(type)
Parameters
| Parameter | Description |
| type | Required. The type of event. AnimationEvent ClipboardEvent DragEvent FocusEvent HashChangeEvent InputEvent KeyboardEvent MouseEvent PageTransitionEvent PopStateEvent ProgressEvent StorageEvent TouchEvent TransitionEvent UiEvent WheelEvent |
Return Value
| Type | Description |
| Object | An Event object. |
Browser Support
document.createEvent() is a DOM Level 1 (1998) feature.
It is fully supported in all browsers:
| Chrome | IE | Edge | Firefox | Safari | Opera |
| Yes | 9-11 | Yes | Yes | Yes | Yes |