event.initEvent

  • Revision slug: DOM/event.initEvent
  • Revision title: event.initEvent
  • Revision id: 78803
  • Created:
  • Creator: trevorh
  • Is current revision? No
  • Comment 2 words removed

Revision Content

{{ DomRef() }}

Summary

The initEvent method is used to initialize the value of an {{ domxref("event") }} created using {{ domxref("document.createEvent") }}.

Syntax

event.initEvent(type, bubbles, cancelable); 
type
The type of event.
bubbles
A boolean indicating whether the event should bubble up through the event chain or not (see {{ domxref("event.bubbles","bubbles") }}).
cancelable;
A boolean indicating whether the event can be canceled (see {{ domxref("event.cancelable","cancelable") }}).

Example

// create a click event that bubbles up and 
// cannot be canceled 
event.initEvent("click", true, false);

The page on {{ domxref("element.dispatchEvent","dispatchEvent") }} has a more useful example.

Notes

Events initialized in this way must have been created with the {{ domxref("document.createEvent") }} method. initEvent must be called to set the event before it is {{ domxref("element.dispatchEvent","dispatchEvent") }}.

Specification

DOM Level 2 Events: Event.initEvent

{{ languages( { "es": "es/DOM/event.initEvent", "fr": "fr/DOM/event.initEvent", "ja": "ja/DOM/event.initEvent", "pl": "pl/DOM/event.initEvent" } ) }}

Revision Source

<p>{{ DomRef() }}</p>
<h3 id="Summary" name="Summary">Summary</h3>
<p>The <code>initEvent</code> method is used to initialize the value of an {{ domxref("event") }} created using {{ domxref("document.createEvent") }}.</p>
<h3 id="Syntax" name="Syntax">Syntax</h3>
<pre class="eval"><em>event</em>.initEvent(<em>type</em>, <em>bubbles</em>, <em>cancelable</em>); 
</pre>
<dl> <dt><code>type</code></dt> <dd>The type of event.</dd> <dt><code>bubbles</code></dt> <dd>A boolean indicating whether the event should bubble up through the event chain or not (see {{ domxref("event.bubbles","bubbles") }}).</dd> <dt><code>cancelable</code>;</dt> <dd>A boolean indicating whether the event can be canceled (see {{ domxref("event.cancelable","cancelable") }}).</dd>
</dl>
<h3 id="Example" name="Example">Example</h3>
<pre class="eval">// create a click event that bubbles up and 
// cannot be canceled 
event.initEvent("click", true, false);
</pre>
<p>The page on {{ domxref("element.dispatchEvent","dispatchEvent") }} has a more useful example.</p>
<h3 id="Notes" name="Notes">Notes</h3>
<p>Events initialized in this way must have been created with the {{ domxref("document.createEvent") }} method. <code>initEvent</code> must be called to set the event before it is {{ domxref("element.dispatchEvent","dispatchEvent") }}.</p>
<h3 id="Specification" name="Specification">Specification</h3>
<p><a class="external" href="http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-Event-initEvent">DOM Level 2 Events: Event.initEvent</a></p>
<p>{{ languages( { "es": "es/DOM/event.initEvent", "fr": "fr/DOM/event.initEvent", "ja": "ja/DOM/event.initEvent", "pl": "pl/DOM/event.initEvent" } ) }}</p>
Revert to this revision