createEvent method
Creates a Document Object Model (DOM) event of the specified type.
createEvent()/initEvent() constructor pattern for synthetic events is deprecated. See the Synthetic Events page for more information.![]() ![]() |
Syntax
var ppEvent = document.createEvent(eventType);Parameters
- eventType [in]
-
Type: String
One of the following values. Case is not important.
-
Creates a Event object.
-
Same as Event.
-
Creates a CompositionEvent object.
-
Creates a CustomEvent object.
-
Creates a DragEvent object.
-
Creates a FocusEvent object.
-
Creates a KeyboardEvent object.
-
Creates a MessageEvent object.
-
Creates a MouseEvent object.
-
Same as MouseEvent.
-
Creates a MouseWheelEvent object.
-
Creates a MutationEvent object.
-
Same as MutationEvent.
-
Creates a StorageEvent object.
-
Creates a TextEvent object.
-
Creates a UIEvent object
-
Same as UIEvent.
- ppEvent [out, retval]
-
C++ The address of a pointer to IDOMEvent that receives the event object. JavaScript An uninitialized event object.
Return value
Type: IDOMEvent
The address of a pointer to IDOMEvent that receives the event object. An uninitialized event object.Standards information
- The canvas element, Section 1.5
Remarks
If the event object is to be dispatched with dispatchEvent, the appropriate event initialization method must be called. For example, after creating an event of type UIEvent, call initUIEvent to initialize the event object's values.
Security Warning: For security reasons, events generated with createEvent are untrusted and have a isTrusted value of false.
Examples
The following example demonstrates how to create and dispatch a custom event that bubbles and cannot be canceled.
var evt = document.createEvent("Event"); evt.initEvent("custom", true, false); document.getElementById('target').dispatchEvent(evt);
To respond to the custom event created previously, the following example adds an event handler that interacts with the event by setting a expando property named detail.
function reportEvent(evt) { evt.detail = "Success."; } var p = document.getElementById('target'); p.addEventListener("custom", reportEvent, false);
See also
- document
- Reference
- initCompositionEvent
- initCustomEvent
- initDragEvent
- initEvent
- initFocusEvent
- initKeyboardEvent
- initMessageEvent
- initMouseEvent
- initMouseWheelEvent
- initMutationEvent
- initStorageEvent
- initTextEvent
- initUIEvent
- initWheelEvent

