createEvent() Event Method
THE WORLD'S LARGEST WEB DEVELOPER SITE

createEvent() Event Method

❮ DOM Events ❮ Event Object

Example

Simulate a mouseover event:

var x = document.createEvent("MouseEvent");
x.initMouseEvent("mouseover", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);

document.getElementById("myDiv").dispatchEvent(x);
Try it Yourself »

Definition and Usage

The createEvent() method creates an event object.

The event can be of any legal event type, and must be initialized before use.


Browser Support

The numbers in the table specify the first browser version that fully supports the method.

Method
createEvent() Yes Yes Yes Yes Yes

Syntax

document.createEvent(type)

Parameter Values

Parameter Description
type Required. A String that specifies the type of the event.

Possible values:

AnimatioEvent
ClipboardEvent
DragEvent
FocusEvent
HashChangeEvent
InputEvent
KeyboardEvent
MouseEvent
PageTransitionEvent
PopStateEvent
ProgressEvent
StorageEvent
TouchEvent
TransitionEvent
UiEvent
WheelEvent

Technical Details

Return Value: An Event object

❮ DOM Events ❮ Event Object