Package | dom.events |
Class | public class Event |
Inheritance | Event Object |
Subclasses | CustomEvent, LSLoadEvent, LSProgressEvent, MessageEvent, MutationEvent, StorageEvent, UIEvent |
Introduced in: | DOM 2 Events |
Modified in: | DOM 3 Events |
To create an instance of the Event interface, use the DocumentEvent.createEvent("Event") method call.
See also
Property | Defined 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 |
Method | Defined By | ||
---|---|---|---|
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 |
Constant | Defined 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 |
DOM 2 Events bubbles | property |
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.
public function get bubbles():Boolean
See also
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 cancelable | property |
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.
public function get cancelable():Boolean
See also
DOM 2 Events currentTarget | property |
currentTarget:EventTarget
[read-only] Introduced in: | DOM 2 Events |
Identifies the current target for the event, as the event traverses the DOM.
public function get currentTarget():EventTarget
See also
DOM 3 Events defaulPrevented | property |
defaulPrevented:Boolean
[read-only] Introduced in: | DOM 3 Events |
Used to indicate whether Event.preventDefault() has been called for this event.
public function get defaulPrevented():Boolean
See also
DOM 2 Events eventPhase | property |
eventPhase:Number
[read-only] Introduced in: | DOM 2 Events |
Used to indicate which phase of event flow is currently being accomplished.
public function get eventPhase():Number
See also
explicitOriginalTarget | property |
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.
public function get explicitOriginalTarget():nsIDOMEventTarget
See also
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>
isTrusted | property |
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
public function get isTrusted():Boolean
See also
DOM 3 Events namespaceURI | property |
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.
public function get namespaceURI():DOMString
See also
originalTarget | property |
originalTarget:*
[read-only] Non-standard (Mozilla)
The original target of the event before any retargetings.
public function get originalTarget():*
See also
DOM 2 Events target | property |
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.
public function get target():EventTarget
See also
<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 timeStamp | property |
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.
public function get timeStamp():DOMTimeStamp
See also
<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 type | property |
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.
public function get type():DOMString
See also
<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>
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
<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
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
HTML 4.0 abort | Constant |
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.
Title | Value |
---|---|
Cancelable | No |
Bubbles | Yes |
Target | Element |
Context info | UIEvent.view is in use. |
See also
DOM 2 Events AT_TARGET | Constant |
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_PHASE | Constant |
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_PHASE | Constant |
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 change | Constant |
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.
Title | Value |
---|---|
Cancelable | No |
Bubbles | Yes |
Target | Element |
Context info | UIEvent.view is in use. |
See also
HTML 4.0 error | Constant |
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.
Title | Value |
---|---|
Cancelable | No |
Bubbles | Yes |
Target | Element |
Context info | UIEvent.view is in use. |
See also
HTML 4.0 load | Constant |
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.
Title | Value |
---|---|
Cancelable | No |
Bubbles | No |
Target | Document, Element |
Context info | UIEvent.view is in use. |
See also
HTML 4.0 reset | Constant |
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.
Title | Value |
---|---|
Cancelable | Yes |
Bubbles | Yes |
Target | Element |
Context info | UIEvent.view is in use. |
See also
HTML 4.0 select | Constant |
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.
Title | Value |
---|---|
Cancelable | No |
Bubbles | Yes |
Target | Element |
Context info | UIEvent.view is in use. |
See also
HTML 4.0 submit | Constant |
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.
Title | Value |
---|---|
Cancelable | Yes |
Bubbles | Yes |
Target | Element |
Context info | UIEvent.view is in use. |
See also
HTML 4.0 unload | Constant |
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.
Title | Value |
---|---|
Cancelable | No |
Bubbles | No |
Target | Document, Element |
Context info | UIEvent.view is in use. |
See also