createEvent() Event Method

Definition and Usage

createEvent() The method creates an event object.

The event can be any valid event type and must be initialized before use.

Example

Simulate 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

Syntax

document.createEvent(type)

Parameter Value

Parameter Description
type

Required. String, specifies the event type.

Possible Values:

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

Technical Details

Return Value: Event Object

Browser Support

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

Properties Chrome IE Firefox Safari Opera
createEvent() Support Support Support Support Support