MDN may have intermittent access issues April 18 13:00 - April 19 01:00 UTC. See whistlepig.mozilla.org for all notifications.

mozilla

Revision 380023 of EventTarget

  • Revision slug: DOM/EventTarget
  • Revision title: EventTarget
  • Revision id: 380023
  • Created:
  • Creator: teoli
  • Is current revision? No
  • Comment

Revision Content

{{ DomRef() }}

An EventTarget is a DOM interface implemented by objects that can receive DOM events and have listeners for them. The most common objects implemented the EventTarget interface are DOM elements, although other objects can implement it too, for example {{domxref("document")}}, {{domxref("window")}}, {{domxref("XMLHttpRequest")}}, {{domxref("AudioNode")}}, and others.

Methods

{{domxref("EventTarget.addEventListener()")}}
Register an event handler of a specific event type on the EventTarget.
{{domxref("EventTarget.removeEventListener()")}}
Removes an event listener from the EventTarget.
{{domxref("EventTarget.dispatchEvent()")}}
Dispatch an event to this EventTarget.

Specifications

Specification Status Comment
{{SpecName('DOM WHATWG', '#interface-eventtarget', 'EventTarget')}} {{Spec2('DOM WHATWG')}} No change.
{{SpecName('DOM3 Events', 'DOM3-Events.html#interface-EventTarget', 'EventTarget')}} {{Spec2('DOM3 Events')}} A few parameters are now optional (listener), or accepts the null value (useCapture).
{{SpecName('DOM2 Events', 'events.html#Events-EventTarget', 'EventTarget')}} {{Spec2('DOM2 Events')}} Initial definition.

Browser compatibility

{{ CompatibilityTable() }}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 1.0 {{ CompatGeckoDesktop("1") }} 9.0 7 1.0
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support 1.0 {{ CompatGeckoMobile("1") }} 9.0 6.0 1.0

See Also

Revision Source

<p>{{ DomRef() }}</p>
<p>An <code>EventTarget</code> is a DOM interface implemented by objects that can receive DOM events and have listeners for them. The most common objects implemented the <code>EventTarget</code> interface are <a href="/en-US/docs/DOM/element">DOM elements</a>, although other objects can implement it too, for example {{domxref("document")}}, {{domxref("window")}}, {{domxref("XMLHttpRequest")}}, {{domxref("AudioNode")}}, and others.</p>
<h2 id="Methods" name="Methods">Methods</h2>
<dl>
  <dt>
    {{domxref("EventTarget.addEventListener()")}}</dt>
  <dd>
    Register an event handler of a specific event type on the <code>EventTarget</code>.</dd>
  <dt>
    {{domxref("EventTarget.removeEventListener()")}}</dt>
  <dd>
    Removes an event listener from the <code>EventTarget</code>.</dd>
  <dt>
    {{domxref("EventTarget.dispatchEvent()")}}</dt>
  <dd>
    Dispatch an event to this <code>EventTarget</code>.</dd>
</dl>
<h2 id="Specification" name="Specification">Specifications</h2>
<table class="standard-table">
  <tbody>
    <tr>
      <th scope="col">Specification</th>
      <th scope="col">Status</th>
      <th scope="col">Comment</th>
    </tr>
    <tr>
      <td>{{SpecName('DOM WHATWG', '#interface-eventtarget', 'EventTarget')}}</td>
      <td>{{Spec2('DOM WHATWG')}}</td>
      <td>No change.</td>
    </tr>
    <tr>
      <td>{{SpecName('DOM3 Events', 'DOM3-Events.html#interface-EventTarget', 'EventTarget')}}</td>
      <td>{{Spec2('DOM3 Events')}}</td>
      <td>A few parameters are now optional (<code>listener</code>), or accepts the <code>null</code> value (<code>useCapture</code>).</td>
    </tr>
    <tr>
      <td>{{SpecName('DOM2 Events', 'events.html#Events-EventTarget', 'EventTarget')}}</td>
      <td>{{Spec2('DOM2 Events')}}</td>
      <td>Initial definition.</td>
    </tr>
  </tbody>
</table>
<h2 id="Browser_Compatibility" name="Browser_Compatibility">Browser compatibility</h2>
<p>{{ CompatibilityTable() }}</p>
<div id="compat-desktop">
  <table class="compat-table">
    <tbody>
      <tr>
        <th>Feature</th>
        <th>Chrome</th>
        <th>Firefox (Gecko)</th>
        <th>Internet Explorer</th>
        <th>Opera</th>
        <th>Safari (WebKit)</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>1.0</td>
        <td>{{ CompatGeckoDesktop("1") }}</td>
        <td>9.0</td>
        <td>7</td>
        <td>1.0</td>
      </tr>
    </tbody>
  </table>
</div>
<div id="compat-mobile">
  <table class="compat-table">
    <tbody>
      <tr>
        <th>Feature</th>
        <th>Android</th>
        <th>Firefox Mobile (Gecko)</th>
        <th>IE Mobile</th>
        <th>Opera Mobile</th>
        <th>Safari Mobile</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>1.0</td>
        <td>{{ CompatGeckoMobile("1") }}</td>
        <td>9.0</td>
        <td>6.0</td>
        <td>1.0</td>
      </tr>
    </tbody>
  </table>
</div>
<h2 id="See_Also">See Also</h2>
<ul>
  <li><a href="/en-US/docs/DOM/Mozilla_event_reference" title="/en-US/docs/DOM/Mozilla_event_reference">Mozilla event reference</a></li>
  <li>{{domxref("Event")}}</li>
</ul>
Revert to this revision