Export (0) Print
Expand All

createEvent method

Creates a Document Object Model (DOM) event of the specified type.

The canvas element, Section 1.5Internet Explorer 9

 

Syntax

var ppEvent = document.createEvent(eventType);

Parameters

eventType [in]

Type: String

One of the following values. Case is not important.

Event

Creates a Event object.

Events

Same as Event.

CompositionEvent

Creates a CompositionEvent object.

CustomEvent

Creates a CustomEvent object.

DragEvent

Creates a DragEvent object.

FocusEvent

Creates a FocusEvent object.

KeyboardEvent

Creates a KeyboardEvent object.

MessageEvents

Creates a MessageEvent object.

MouseEvent

Creates a MouseEvent object.

MouseEvents

Same as MouseEvent.

MouseWheelEvent

Creates a MouseWheelEvent object.

MutationEvent

Creates a MutationEvent object.

MutationEvents

Same as MutationEvent.

StorageEvent

Creates a StorageEvent object.

TextEvent

Creates a TextEvent object.

UIEvent

Creates a UIEvent object

UIEvents

Same as UIEvent.

ppEvent [out, retval]
C++The address of a pointer to IDOMEvent that receives the event object.
JavaScriptAn 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

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

 

 

Show:
© 2014 Microsoft