This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

initEvent

Summary

Initializes a new generic event that the createEvent method created.

Method of dom/Eventdom/Event

Syntax

 event.initEvent(eventType, canBubble, cancelable);

Parameters

eventType

Data-type
String

The name of the event. Sets the value for the type property.

canBubble

Data-type
Boolean

Whether the event propagates upward. Sets the value for the bubbles property.

cancelable

Data-type
Boolean

Whether the event is cancelable and so preventDefault can be called. Sets the value for the cancelable property.

Return Value

No return value

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);

Usage

 Use this method before the   dispatchEvent method dispatches the event object, to set some properties of the event.

Notes

After the event is dispatched, its properties cannot be changed.

Related specifications

DOM Level 3 Events
Working Draft

See also

Related pages

Attributions