initEvent method
Initializes a new generic event that the createEvent method created.
createEvent()/initEvent() constructor pattern for synthetic events is deprecated. See the Synthetic Events page for more information.![]() ![]() |
Syntax
object.initEvent(eventType, canBubble, cancelable)Parameters
- eventType [in]
-
Type: String
The event type.
- canBubble [in]
-
Type: Boolean
- cancelable [in]
-
Type: Boolean
Return value
Type: HRESULT
If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
Standards information
Remarks
You can call the initEvent method only before the dispatchEvent method dispatches the event object. After the event is dispatched, its properties cannot be changed.
Examples
The following code example creates a custom event that bubbles but cannot be canceled.
var evt = document.createEvent("Event"); evt.initEvent("custom", true, false); document.getElementById('target').dispatchEvent(evt);
See also
- BeforeUnloadEvent
- CompositionEvent
- CustomEvent
- DragEvent
- Event
- FocusEvent
- KeyboardEvent
- MessageEvent
- MouseEvent
- MouseWheelEvent
- MSSiteModeEvent
- MutationEvent
- StorageEvent
- SVGZoomEvent
- TextEvent
- UIEvent
- Reference
- bubbles
- cancelable
- dispatchEvent

