Packagedom.events
Classpublic class Event
InheritanceEvent Inheritance Object
Subclasses CustomEvent, LSLoadEvent, LSProgressEvent, MessageEvent, MutationEvent, StorageEvent, UIEvent

Introduced in: DOM 2 Events 
Modified in: DOM 3 Events 

The Event interface is used to provide contextual information about an event to the listener processing the event. An object which implements the Event interface is passed as the parameter to an EventListener. The object passed to the event listener may also implement derived interfaces that provide access to information directly relating to the type of event they represent.

To create an instance of the Event interface, use the DocumentEvent.createEvent("Event") method call.

See also

W3C - DOM 3 Events: Event


Public Properties
 PropertyDefined By
  DOM 2 Events bubbles : Boolean
[read-only] Used to indicate whether or not an event is a bubbling event.
Event
  DOM 2 Events cancelable : Boolean
[read-only] Indicates whether the event is cancelable or not.
Event
  DOM 2 Events currentTarget : EventTarget
[read-only] Identifies the current target for the event, as the event traverses the DOM.
Event
  DOM 3 Events defaulPrevented : Boolean
[read-only] Used to indicate whether Event.preventDefault() has been called for this event.
Event
  DOM 2 Events eventPhase : Number
[read-only] Used to indicate which phase of event flow is currently being accomplished.
Event
  Non-Standard explicitOriginalTarget : nsIDOMEventTarget
[read-only] The explicit original target of the event.
Event
  Non-Standard isTrusted : Boolean
[read-only] Determines if the event was from the user or script generated.
Event
  DOM 3 Events namespaceURI : DOMString
[read-only] The namespace URI associated with this event at initialization time, or null if it is unspecified.
Event
  Non-Standard originalTarget : *
[read-only] The original target of the event before any retargetings.
Event
  DOM 2 Events target : EventTarget
[read-only] Used to indicate the event target.
Event
  DOM 2 Events timeStamp : DOMTimeStamp
[read-only] Used to specify the time at which the event was created in milliseconds relative to 1970-01-01T00:00:00Z.
Event
  DOM 2 Events type : DOMString
[read-only] The local name of the event type.
Event
Public Methods
 MethodDefined By
  
DOM 2 Events initEvent(typeArg:DOMString, canBubbleArg:Boolean, cancelableArg:Boolean):void
Initializes attributes of an Event created through the DocumentEvent.createEvent method.
Event
  
DOM 3 Events initEventNS(namespaceURIArg:DOMString, typeArg:DOMString, canBubbleArg:Boolean, cancelableArg:Boolean):void
Initializes attributes of an Event object.
Event
  
 Obsolete preventBubble():void
Prevents the event from bubbling.
Event
  
 Obsolete preventCapture():void
This method is deprecated in favor of standard stopPropagation and is removed in Gecko 1.9.
Event
  
DOM 2 Events preventDefault():void
Cancels the event if it is cancelable, without stopping further propagation of the event.
Event
  
DOM 3 Events stopImmediatePropogation():void
Prevents other event listeners from being triggered and, unlike Event.stopPropagation() its effect is immediate .
Event
  
DOM 2 Events stopPropogation():void
Prevents other event listeners from being triggered but its effect is deferred until all event listeners attached on the Event.currentTarget have been triggered .
Event
Public Constants
 ConstantDefined By
  HTML 4.0 abort : String = abort
[static] Loading of a resource has been aborted.
Event
  DOM 2 Events AT_TARGET : Number = 2
[static] The current event is in the target phase, i.e.
Event
  DOM 2 Events BUBBLING_PHASE : Number = 3
[static] The current event phase is the bubbling phase.
Event
  DOM 2 Events CAPTURING_PHASE : Number = 1
[static] The current event phase is the capture phase.
Event
  HTML 4.0 change : String = change
[static] A control loses the input focus and its value has been modified since gaining focus.
Event
  HTML 4.0 error : String = error
[static] A resource failed to load, or has been loaded but cannot be interpreted according to its semantics such as an invalid image, a script execution error, or non-well-formed XML.
Event
  HTML 4.0 load : String = load
[static] The DOM Implementation finishes loading the resource (such as the document) and any dependent resources (such as images, style sheets, or scripts).
Event
  HTML 4.0 reset : String = reset
[static] A form, such as a [HTML 4.01] or [XHTML 1.0] form, is reset.
Event
  HTML 4.0 select : String = select
[static] A user selects some text.
Event
  HTML 4.0 submit : String = submit
[static] A form, such as a [HTML 4.01] or [XHTML 1.0] form, is submitted.
Event
  HTML 4.0 unload : String = unload
[static] The DOM implementation removes from the environment the resource (such as the document) or any dependent resources (such as images, style sheets, scripts).
Event
Property Detail
DOM 2 Events bubblesproperty
bubbles:Boolean  [read-only]

Introduced in: DOM 2 Events 

Used to indicate whether or not an event is a bubbling event. If the event can bubble the value is true, otherwise the value is false.


Implementation
    public function get bubbles():Boolean

See also


Example
         function goInput(e) {
             // checks bubbles and
             if not e.bubbles {
                 // passes event along if it's not
                 passItOn(e); 
             }
             // already bubbling
             doOutput(e)
         }
DOM 2 Events cancelableproperty 
cancelable:Boolean  [read-only]

Introduced in: DOM 2 Events 

Indicates whether the event is cancelable or not.

Note: Whether an event can be canceled or not is something that's determined when that event is initialized.

Note: To cancel an event, call the preventDefault method on the event. This keeps the implementation from executing the default action that is associated with the event.


Implementation
    public function get cancelable():Boolean

See also

DOM 2 Events currentTargetproperty 
currentTarget:EventTarget  [read-only]

Introduced in: DOM 2 Events 

Identifies the current target for the event, as the event traverses the DOM.


Implementation
    public function get currentTarget():EventTarget

See also

DOM 3 Events defaulPreventedproperty 
defaulPrevented:Boolean  [read-only]

Introduced in: DOM 3 Events 

Used to indicate whether Event.preventDefault() has been called for this event.


Implementation
    public function get defaulPrevented():Boolean

See also

DOM 2 Events eventPhaseproperty 
eventPhase:Number  [read-only]

Introduced in: DOM 2 Events 

Used to indicate which phase of event flow is currently being accomplished.


Implementation
    public function get eventPhase():Number

See also

explicitOriginalTargetproperty 
explicitOriginalTarget:nsIDOMEventTarget  [read-only]

Non-standard (Mozilla)

The explicit original target of the event.

If the event was retargeted for some reason other than an anonymous boundary crossing, this will be set to the target before the retargeting occurs. For example, mouse events are retargeted to their parent node when they happen over text nodes (see bug 185889), and in that case currentTarget will show the parent and explicitOriginalTarget will show the text node.

explicitOriginalTarget differs from originalTarget in that it will never contain anonymous content.


Implementation
    public function get explicitOriginalTarget():nsIDOMEventTarget

See also


Example
This property can be used with <command> to get the event details of the original object calling the command.
         function myCommand(ev) {
             alert(ev.explicitOriginalTarget.nodeName); // returns 'menuitem'
         }
         
         
         <command id="my-cmd-anAction" oncommand="myCommand(event);"/>
         
         <menulist><menupopup>
             <menuitem label="Get my element name!" command="my-cmd-anAction"/>
         </menupopup></menulist>
isTrustedproperty 
isTrusted:Boolean  [read-only]

Non-standard (Mozilla)

Determines if the event was from the user or script generated. Returns true if the user caused the event to be dispatched.

Note: Can't find any more information on this property


Implementation
    public function get isTrusted():Boolean

See also

DOM 3 Events namespaceURIproperty 
namespaceURI:DOMString  [read-only]

Introduced in: DOM 3 Events 

The namespace URI associated with this event at initialization time, or null if it is unspecified. DOM Level 2 Events initialization methods, such as Event.initEvent(), set the value to null.


Implementation
    public function get namespaceURI():DOMString

See also

originalTargetproperty 
originalTarget:*  [read-only]

Non-standard (Mozilla)

The original target of the event before any retargetings.


Implementation
    public function get originalTarget():*

See also

DOM 2 Events targetproperty 
target:EventTarget  [read-only]

Introduced in: DOM 2 Events 

Used to indicate the event target. This attribute contains the target node when used with the Event dispatch and DOM event flow.


Implementation
    public function get target():EventTarget

See also


Example
<html>
         <head>
         <title>target example</title>
         <script type="text/javascript">
         
         function highlightTarget(evt) {
             evt.target.style.backgroundColor = 'blue';
         }
         
         function resetTarget(evt) {
               evt.target.style.backgroundColor = 'silver';
         }
         
         </script>
         </head>
         
         <body onmousedown="highlightTarget(event)" onmouseup="resetTarget(event)">
         
         <p>This example demonstrates how, by using event propagation, two event
         handler functions in the body element can use the <i>target</i> property
         to distinguish between, and process, all other bubbleable events occuring
         lower down the DOM. Note: not all events can bubble up the DOM.</p>
         
         <p>As an event lower down the DOM bubbles up and reaches the body
         object, the <i>target</i> property contains the object reference of the
         original event target. In this case which element in the document
         received an onmousedown or onmouseup event.</p>
         
         <p>This allows the event handlers of the body object to process bubbleable
         events occuring lower down the DOM structure, which means there is no need
         to attach the event handlers to every button & para element of the page.</p>
         
         <button>button 1</button><br />
         <button>button 2</button><br />
         
         <button>button 3</button><br />
         <button>button 4</button><br />
         <button>button 5</button><br />
         <button>button 6</button><br />
         
         <button>button 7</button><br />
         
         </body>
         </html>
DOM 2 Events timeStampproperty 
timeStamp:DOMTimeStamp  [read-only]

Introduced in: DOM 2 Events 

Used to specify the time at which the event was created in milliseconds relative to 1970-01-01T00:00:00Z. Due to the fact that some systems may not provide this information the value of timeStamp may be not available for all events. When not available, the value is 0.


Implementation
    public function get timeStamp():DOMTimeStamp

See also


Example
         <html>
         <head>
         
         <title>timeStamp example</title>
         
         <script type="text/javascript">
         function getTime(event) {
             document.getElementById("time").firstChild.nodeValue = event.timeStamp;
         }
         </script>
         </head>
         
         <body onkeypress="getTime(event)">
         
         <p>Press any key to get the current timestamp
         for the onkeypress event.</p>
         <p>timeStamp: <span id="time">-</span></p>
         
         </body>
         
         </html>
DOM 2 Events typeproperty 
type:DOMString  [read-only]

Introduced in: DOM 2 Events 

The local name of the event type. The name must be an NCName as defined in [XML Namespaces 1.1] and is case-sensitive.

Note: The type must be an XML name.


Implementation
    public function get type():DOMString

See also


Example
         <html>
         <head>
         
         <title>type example</title>
         
         <script type="text/javascript">
         var currEvent = null;
         
         function getEvtType(evt) {
             currEvent = evt.type;
             document.getElementById("Etype").firstChild.nodeValue = currEvent;
         }
         
         </script>
         </head>
         
         <body
           onkeydown="getEvtType(event)"
           onkeyup="getEvtType(event)"
           onmousedown="getEvtType(event)"
           onmouseup="getEvtType(event)">
         
         <p>Press any key or click the mouse to get the event type.</p>
         <p>Event type: <span id="Etype">-</span></p>
         
         </body>
         
         </html>
Method Detail
DOM 2 Events initEvent()method
public function initEvent(typeArg:DOMString, canBubbleArg:Boolean, cancelableArg:Boolean):void

Introduced in: DOM 2 Events 

Initializes attributes of an Event created through the DocumentEvent.createEvent method. This method may only be called before the Event has been dispatched via the EventTarget.dispatchEvent() method. If the method is called several times before invoking EventTarget.dispatchEvent, only the final invocation takes precedence. This method has no effect if called after the event has been dispatched. If called from a subclass of the Event interface only the values specified in this method are modified, all other attributes are left unchanged.

This method sets the Event.type attribute to typeArg, and Event.namespaceURI to null. To initialize an event with a namespace URI, use the Event.initEventNS() method.

Parameters

typeArg:DOMString — Specifies Event.type, the local name of the event type.
 
canBubbleArg:Boolean — Specifies Event.bubbles. This parameter overrides the intrinsic bubbling behavior of the event.
 
cancelableArg:Boolean — Specifies Event.cancelable. This parameter overrides the intrinsic cancelable behavior of the event.

See also

DOM 3 Events initEventNS()method 
public function initEventNS(namespaceURIArg:DOMString, typeArg:DOMString, canBubbleArg:Boolean, cancelableArg:Boolean):void

Introduced in: DOM 3 Events 

Initializes attributes of an Event object. This method has the same behavior as Event.initEvent().

Parameters

namespaceURIArg:DOMString — Specifies Event.namespaceURI, the namespace URI associated with this event, or null if no namespace.
 
typeArg:DOMString — Specifies Event.type, the local name of the event type.
 
canBubbleArg:Boolean — Specifies Event.bubbles. This parameter overrides the intrinsic bubbling behavior of the event.
 
cancelableArg:Boolean — Specifies Event.cancelable. This parameter overrides the intrinsic cancelable behavior of the event.

See also

preventBubble()method 
public function preventBubble():void

Obsolete

Prevents the event from bubbling. This method is deprecated in favor of standard stopPropagation and is removed in Gecko 1.9.

See also

preventCapture()method 
public function preventCapture():void

Obsolete

This method is deprecated in favor of standard stopPropagation and is removed in Gecko 1.9.

See also

DOM 2 Events preventDefault()method 
public function preventDefault():void

Introduced in: DOM 2 Events 

Cancels the event if it is cancelable, without stopping further propagation of the event. Signifies that the event is to be canceled, meaning any default action normally taken by the implementation as a result of the event will not occur (see also Default actions and cancelable events). Calling this method for a non-cancelable event has no effect.

Note: This method does not stop the event propagation; use Event.stopPropagation() or Event.stopImmediatePropagation() for that effect.

Note: Calling preventDefault during any stage of event flow cancels the event, meaning that any default action normally taken by the implementation as a result of the event will not occur.

See also


Example
Toggling a checkbox is the default action of clicking on a checkbox. This example demonstrates how to prevent that happening:
         <html>
         <head>
         <title>preventDefault example</title>
         
         <script type="text/javascript">
         
         function stopDefAction(evt) {
             evt.preventDefault();
         }
         </script>
         </head>
         
         <body>
         
         <p>Please click on the checkbox control.</p>
         
         <form>
         <input type="checkbox" onclick="stopDefAction(event);"/>
         <label for="checkbox">Checkbox</label>
         
         </form>
         
         </body>
         </html>
DOM 3 Events stopImmediatePropogation()method 
public function stopImmediatePropogation():void

Introduced in: DOM 3 Events 

Prevents other event listeners from being triggered and, unlike Event.stopPropagation() its effect is immediate . Once it has been called, further calls to this method have no additional effect.

Note: This method does not prevent the default action from being invoked; use Event.preventDefault() for that effect.

See also


Example
This example demonstrates how events fire and are handled in the DOM in a very simple way. When the BODY of this HTML document loads, an event listener is registered with the top row of the TABLE. The event listener handles the event by executing the function stopEvent, which changes the value in the bottom cell of the table.

However, stopEvent also calls an event object method, event.stopPropagation, which keeps the event from bubbling any further up into the DOM. Note that the table itself has an onclick event handler that ought to display a message when the table is clicked. But the stopEvent method has stopped propagation, and so after the data in the table is updated, the event phase is effectively ended, and an alert box is displayed to confirm this.

         <html>
         <head>
         <title>Event Propagation</title>
         
         <style type="text/css">
             #t-daddy { border: 1px solid red }
             #c1 { background-color: pink; }
         </style>
         
         <script type="text/javascript">
         
         function stopEvent(ev) {
             c2 = document.getElementById("c2");
             c2.innerHTML = "hello";
         
             // this ought to keep t-daddy from getting the click.
             ev.stopPropagation();
             alert("event propagation halted.");
         }
         
         function load() {
             elem = document.getElementById("tbl1");
             elem.addEventListener("click", stopEvent, false);
         }
         </script>
         </head>
         
         <body onload="load();">
         
         <table id="t-daddy" onclick="alert('hi');">
             <tr id="tbl1">
                 <td id="c1">one</td>
             </tr>
             <tr>
                 <td id="c2">two</td>
             </tr>
         </table>
         
         </body>
         </html>
DOM 2 Events stopPropogation()method 
public function stopPropogation():void

Introduced in: DOM 2 Events 

Prevents other event listeners from being triggered but its effect is deferred until all event listeners attached on the Event.currentTarget have been triggered . Once it has been called, further calls to this method have no additional effect.

Note: This method does not prevent the default action from being invoked; use Event.preventDefault() for that effect.

See also

Constant Detail
HTML 4.0 abortConstant
public static const abort:String = abort

Introduced in: HTML 4.0 
Modified in: DOM 3 Events 

Loading of a resource has been aborted.

Note: Dispatched from UIEvent if generated from a user interface, Event otherwise.

TitleValue
CancelableNo
BubblesYes
TargetElement
Context infoUIEvent.view is in use.

See also

DOM 2 Events AT_TARGETConstant 
public static const AT_TARGET:Number = 2

Introduced in: DOM 2 Events 

The current event is in the target phase, i.e. it is being evaluated at the event target.

See also

DOM 2 Events BUBBLING_PHASEConstant 
public static const BUBBLING_PHASE:Number = 3

Introduced in: DOM 2 Events 

The current event phase is the bubbling phase.

See also

DOM 2 Events CAPTURING_PHASEConstant 
public static const CAPTURING_PHASE:Number = 1

Introduced in: DOM 2 Events 

The current event phase is the capture phase.

See also

HTML 4.0 changeConstant 
public static const change:String = change

Introduced in: HTML 4.0 
Modified in: DOM 3 Events 

A control loses the input focus and its value has been modified since gaining focus. This event type is dispatched before the event type blur.

Note: Dispatched from UIEvent if generated from a user interface, Event otherwise.

TitleValue
CancelableNo
BubblesYes
TargetElement
Context infoUIEvent.view is in use.

See also

HTML 4.0 errorConstant 
public static const error:String = error

Introduced in: HTML 4.0 
Modified in: DOM 3 Events 

A resource failed to load, or has been loaded but cannot be interpreted according to its semantics such as an invalid image, a script execution error, or non-well-formed XML.

Note: Dispatched from UIEvent if generated from a user interface, Event otherwise.

TitleValue
CancelableNo
BubblesYes
TargetElement
Context infoUIEvent.view is in use.

See also

HTML 4.0 loadConstant 
public static const load:String = load

Introduced in: HTML 4.0 
Modified in: DOM 3 Events 

The DOM Implementation finishes loading the resource (such as the document) and any dependent resources (such as images, style sheets, or scripts). Dependent resources that fail to load will not prevent this event from firing if the resource that loaded them is still accessible via the DOM. If this event type is dispatched, implementations are required to dispatch this event at least on the Document node.

Note: Dispatched from UIEvent if generated from a user interface, Event otherwise.

TitleValue
CancelableNo
BubblesNo
TargetDocument, Element
Context infoUIEvent.view is in use.

See also

HTML 4.0 resetConstant 
public static const reset:String = reset

Introduced in: HTML 4.0 
Modified in: DOM 3 Events 

A form, such as a [HTML 4.01] or [XHTML 1.0] form, is reset.

Note: Dispatched from UIEvent if generated from a user interface, Event otherwise.

TitleValue
CancelableYes
BubblesYes
TargetElement
Context infoUIEvent.view is in use.

See also

HTML 4.0 selectConstant 
public static const select:String = select

Introduced in: HTML 4.0 
Modified in: DOM 3 Events 

A user selects some text. DOM Level 3 Events does not provide contextual information to access the selected text. The selection occured before the dispatch of this event type.

Note: Dispatched from UIEvent if generated from a user interface, Event otherwise.

TitleValue
CancelableNo
BubblesYes
TargetElement
Context infoUIEvent.view is in use.

See also

HTML 4.0 submitConstant 
public static const submit:String = submit

Introduced in: HTML 4.0 
Modified in: DOM 3 Events 

A form, such as a [HTML 4.01] or [XHTML 1.0] form, is submitted.

Note: Dispatched from UIEvent if generated from a user interface, Event otherwise.

TitleValue
CancelableYes
BubblesYes
TargetElement
Context infoUIEvent.view is in use.

See also

HTML 4.0 unloadConstant 
public static const unload:String = unload

Introduced in: HTML 4.0 
Modified in: DOM 3 Events 

The DOM implementation removes from the environment the resource (such as the document) or any dependent resources (such as images, style sheets, scripts). The document is unloaded after the dispatch of this event type. If this event type is dispatched, implementations are required to dispatch this event at least on the Document node.

Note: Dispatched from UIEvent if generated from a user interface, Event otherwise.

TitleValue
CancelableNo
BubblesNo
TargetDocument, Element
Context infoUIEvent.view is in use.

See also