event.initEvent

  • Revision slug: DOM/event.initEvent
  • Revision title: event.initEvent
  • Revision id: 372969
  • Created:
  • Creator: Ms2ger
  • Is current revision? No
  • Comment

Revision Content

The initEvent method is deprecated. Use event constructors instead.

{{ 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

Revision Source

<div class="warning">
  <p>The initEvent method is deprecated. Use event constructors instead.</p>
</div>
<div>
  {{ DomRef() }}</div>
<h2 id="Summary" name="Summary">Summary</h2>
<p>The <code>initEvent</code> method is used to initialize the value of an {{ domxref("event") }} created using {{ domxref("document.createEvent") }}.</p>
<h2 id="Syntax" name="Syntax">Syntax</h2>
<pre class="syntaxbox">
<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>
<h2 id="Example" name="Example">Example</h2>
<pre class="brush:js">
// 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>
<h2 id="Notes" name="Notes">Notes</h2>
<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>
<h2 id="Specification" name="Specification">Specification</h2>
<ul>
  <li><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></li>
</ul>
Revert to this revision