Copyright © 2008 W3C ® ( MIT , ERCIM , Keio), All Rights Reserved. W3C liability, trademark and document use rules apply.
This specification defines the Document Object Model Events Level 3, a generic platform- and language-neutral event system which allows registration of event handlers, describes event flow through a tree structure, and provides basic contextual information for each event. The Document Object Model Events Level 3 builds on the Document Object Model Events Level 2 [DOM Level 2 Events].
This document is for review by the WebAPI Working Group and is subject to change without notice. This document has no formal standing within W3C. Please consult the group's home page and the W3C technical reports index for information about the latest publications by this group.
Copyright © 2008 World Wide Web Consortium, (Massachusetts Institute of Technology, European Research Consortium for Informatics and Mathematics, Keio University). All Rights Reserved.
This document is published under the W3C® Document Copyright Notice and License. The bindings within this document are published under the W3C® Software Copyright Notice and License. The software license requires "Notice of any changes or modifications to the W3C files, including the date changes were made." Consequently, modified versions of the DOM bindings must document that they do not conform to the W3C standard; in the case of the IDL definitions, the pragma prefix can no longer be 'w3c.org'; in the case of the Java language binding, the package names can no longer be in the 'org.w3c' package.
Note: This section is a copy of the W3C® Document Notice and License and could be found at http://www.w3.org/Consortium/Legal/2002/copyright-documents-20021231.
Copyright © 2008 World Wide Web Consortium, (Massachusetts Institute of Technology, European Research Consortium for Informatics and Mathematics, Keio University). All Rights Reserved.
http://www.w3.org/Consortium/Legal/2002/copyright-documents-20021231
Public documents on the W3C site are provided by the copyright holders under the following license. By using and/or copying this document, or the W3C document from which this statement is linked, you (the licensee) agree that you have read, understood, and will comply with the following terms and conditions:
Permission to copy, and distribute the contents of this document, or the W3C document from which this statement is linked, in any medium for any purpose and without fee or royalty is hereby granted, provided that you include the following on ALL copies of the document, or portions thereof, that you use:
When space permits, inclusion of the full text of this NOTICE should be provided. We request that authorship attribution be provided in any software, documents, or other items or products that you create pursuant to the implementation of the contents of this document, or any portion thereof.
No right to create modifications or derivatives of W3C documents is granted pursuant to this license. However, if additional requirements (documented in the Copyright FAQ) are satisfied, the right to create modifications or derivatives is sometimes granted by the W3C to individuals complying with those requirements.
THIS DOCUMENT IS PROVIDED "AS IS," AND COPYRIGHT HOLDERS MAKE NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, OR TITLE; THAT THE CONTENTS OF THE DOCUMENT ARE SUITABLE FOR ANY PURPOSE; NOR THAT THE IMPLEMENTATION OF SUCH CONTENTS WILL NOT INFRINGE ANY THIRD PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS.
COPYRIGHT HOLDERS WILL NOT BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF ANY USE OF THE DOCUMENT OR THE PERFORMANCE OR IMPLEMENTATION OF THE CONTENTS THEREOF.
The name and trademarks of copyright holders may NOT be used in advertising or publicity pertaining to this document or its contents without specific, written prior permission. Title to copyright in this document will at all times remain with copyright holders.
Note: This section is a copy of the W3C® Software Copyright Notice and License and could be found at http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231
Copyright © 2008 World Wide Web Consortium, (Massachusetts Institute of Technology, European Research Consortium for Informatics and Mathematics, Keio University). All Rights Reserved.
http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231
This work (and included software, documentation such as READMEs, or other related items) is being provided by the copyright holders under the following license. By obtaining, using and/or copying this work, you (the licensee) agree that you have read, understood, and will comply with the following terms and conditions.
Permission to copy, modify, and distribute this software and its documentation, with or without modification, for any purpose and without fee or royalty is hereby granted, provided that you include the following on ALL copies of the software and documentation or portions thereof, including modifications:
THIS SOFTWARE AND DOCUMENTATION IS PROVIDED "AS IS," AND COPYRIGHT HOLDERS MAKE NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF THE SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY THIRD PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS.
COPYRIGHT HOLDERS WILL NOT BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF ANY USE OF THE SOFTWARE OR DOCUMENTATION.
The name and trademarks of copyright holders may NOT be used in advertising or publicity pertaining to the software without specific, written prior permission. Title to copyright in this software and any associated documentation will at all times remain with copyright holders.
Note: This section is a copy of the W3C® Short Software Notice and could be found at http://www.w3.org/Consortium/Legal/2002/copyright-software-short-notice-20021231
Copyright © 2008 World Wide Web Consortium, (Massachusetts Institute of Technology, European Research Consortium for Informatics and Mathematics, Keio University). All Rights Reserved.
Copyright © [$date-of-software] World Wide Web Consortium, (Massachusetts Institute of Technology, European Research Consortium for Informatics and Mathematics, Keio University). All Rights Reserved. This work is distributed under the W3C® Software License [1] in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
[1] http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231
DOM Events is designed with two main goals. The first goal is the design of an event system which allows registration of event listeners and describes event flow through a tree structure. Additionally, the specification will provide standard modules of events for user interface control and document mutation notifications, including defined contextual information for each of these event modules.
The second goal of DOM Events is to provide a common subset of the current event systems used in DOM Level 0 browsers. This is intended to foster interoperability of existing scripts and content. It is not expected that this goal will be met with full backwards compatibility. However, the specification attempts to achieve this when possible.
This specification is to be understood in the context of the DOM Level 3 Core specification [DOM Level 3 Core] and the general considerations for DOM implementations apply. For example, handling of namespace URIs is discussed in XML Namespaces, and behavior in exceptional circumstances (such as when a null argument is passed when null was not expected) is discussed under DOMException. For additional information about conformance, please see the DOM Level 3 Core specification [DOM Level 3 Core].
An implementation is DOM Level 3 Events conformant if it supports the Core module defined in [DOM Level 2 Core], the Event dispatch and DOM event flow mechanism and the interfaces with their associated semantics defined in Basic interfaces. An implementation conforms to a DOM Level 3 Events module if it conforms to DOM Level 3 Events, the event types defined in the module, and the modules the module depends upon (if any).
An implementation conforms to an event type if it conforms to its associated semantics and DOM interfaces. This includes that event objects that are generated by the implementation are generated as outlined in the tabular definition of the event type.
An implementation which does not conform to an event module can still implement the DOM interfaces associated with it. The DOM application can then create an event object using the DocumentEvent.createEvent() method and dispatch an event type associated with this interface using the EventTarget.dispatchEvent() method.
A DOM application may use the hasFeature(feature, version) method of the DOMImplementation interface with parameter values "Events" and "3.0" (respectively) to determine whether or not DOM Level 3 Events is supported by the implementation, and the implementation must return true. Since DOM Level 3 Events is built on top of DOM Level 2 Events [DOM Level 2 Events], an implementation that returns true for "Events" and "3.0" shall also return true for the parameters "Events" and "2.0". The same holds for the feature strings defined for the individual event modules as applicable. Refer to DOM Features in [DOM Level 3 Core] for additional information.
This section defines the event dispatch mechanism of the event model defined in this specification. Applications may dispatch event objects using the EventTarget.dispatchEvent() method, and implementations must dispatch event objects as if through this method. The behavior of this method depends on the event flow associated with the underlying object. An event flow describes how event objects propagate through a data structure. As an example, when an event object is dispatched to an element in an XML document, the object propagates through parts of the document, as determined by the DOM event flow which is defined at the end of this section.
Figure: graphical representation of an event dispatched in a DOM tree using the DOM event flow [SVG 1.0 version]
Event objects are always dispatched to a node called the event target. At the beginning of the dispatch, implementations must first determine the event object's propagation path. The propagation path is an ordered list of event targets through which the object will pass. The last item in the list is the event target; the preceding items in the list are referred to as the target's ancestors, and the immediately preceding item as the target's parent. Once determined, the propagation path cannot be changed. As an example, in the DOM event flow event listeners might change the position of the target node in the document while the event object is being dispatched; such changes do not affect the propagation path. What if an element is removed from the document altogether? Is there different behavior if the event target is removed versus one of its ancestors?
As the next step the event object accomplishes one or more event phases. This specification defines the following event phases. Event objects accomplish them in the specified order using the partial propagation paths as defined below. A phase is skipped if it is not supported, or if the event object's propagation has been stopped. For example, if the Event.bubbles attribute is set to false, the bubble phase is skipped, and if Event.stopPropagation() has been called prior to the dispatch, all phases will be skipped.
Implementations let event objects accomplish an event phase by applying the following steps while there are pending event targets in the partial propagation path for this phase and the event object's propagation has not been stopped through Event.stopPropagation().
First, the implementation must determine the current target. This is the next pending event target in the partial propagation path, starting with the first. From the perspective of an event listener this is the event target the listener has been registered on.
Next, the implementation must determine the current target's candidate event listeners. This is the list of all event listeners that have been registered on the current target in their order of registration. Once determined, the candidate event listeners cannot be changed; adding or removing listeners does not affect the current target's candidate event listeners.
Finally, the implementation must process all candidate event listeners in order and trigger each listener if all the following conditions are met:
An implementation shall trigger a listener by invoking the EventListener.handleEvent() method or an equivalent binding-specific mechanism.
As the final step of the event dispatch, for reasons of backwards compatibility, the implementation must reset the event object's internal-propagation and default-action-prevention states. This ensures that an event object may be properly dispatched multiple times while also allowing to prevent the event objects propagation or default actions prior to the event dispatch.
The model defined above applies regardless of the specific event flow associated with an event target. Each event flow defines how the propagation path is determined and which event phases are supported. The DOM event flow is an application of this model: the propagation path for a Node object is determined by its Node.parentNode chain, and all events accomplish the capture and target phases. Whether an event accomplishes the bubble phase is defined individually for each event type. An alternate application of this model can be found in [DOM Level 3 Load and Save].
The DOM event model is reentrant. Event listeners may perform actions that cause additional events to be dispatched. Such events are handled in a synchronous manner, the event propagation that causes the event listener to be triggered will resume only after the event dispatch of the new event is completed.
Event objects can have default actions associated with them. These are actions the implementation will perform in combination with the dispatch of the event object, usually after the dispatch has been completed, but in exceptional cases also immediately before the event is dispatched. An example is the [HTML 4.01] form element. When the user submits the form (e.g. by pressing on a submit button), the event submit is dispatched to the element and the default action for this event type is generally to send a request to a Web server with the parameters from the form.
Some event objects are cancelable, meaning the default action can be prevented from occuring, or, if the default action is carried out before the dispatch, its effect can be reversed. Whether an event object is cancelable is indicated by the Event.cancelable attribute. Event listeners can cancel default actions of cancelable event objects by invoking the Event.preventDefault() method, and determine whether an event has been canceled through the Event.defaultPrevented attribute while the object is being dispatched, or from the return value of the EventTarget.dispatchEvent() method for event objects dispatched by the DOM application itself.
This specification does not offer features to programatically query if an event object has any default action associated to it or associate new ones. It is expected that other specifications define what default actions, if any, are associated with certain event objects. Further, implementations may associate default actions with events as necessary and appropriate. As an example, an implementation may scroll a document view by a certain amount as default action of a mouse wheel event.
(This section is currently being rewritten.)
Event targets may have associated activation behavior that implementations perform in response to an activation request. As an example, the typical activiation behavior associated with hyperlinks is to follow the link. Activation requests are typically initiated by users through an input device.
In terms of this specification, the activation behavior of the event target is the default action of the event type DOMActivate. DOM applications should use this event type whenever they wish to make or react to an activation request.
Implementations dispatch the DOMActivate event as default action of a click event. This click event is either part of the activation request (e.g., a user requests activiation using a mouse), or synthesized by the implementation to accomodate legacy applications. Context information of such a click event is implementation dependent.
When implementations dispatch a synthesized click event, the expectation is that they do so as default action of another event type. For example, when a user activates a hyperlink using a keyboard, the click event would be dispatched as default action of the respective keyboard event.
Implementations are required to dispatch the synthesized click event as described above even if they do not dispatch such an event (e.g., when activation is requested by a voice command, since this specification does not address event types for voice input).
Note: The activation of an event target is device dependent but is also application dependent, e.g. a link in a document can be activated using a mouse click or a mouse double click.
Each event is associated with a type, called event type and available as the type attribute on the event object. The event type is composed of a local name and a namespace URI as used in [DOM Level 3 Core]. All events defined in this specification are in no namespace.
Depending on the level of DOM support, or the devices used for display (e.g. screen) or interaction (e.g., mouse, keyboard, touch screen, or voice), these event types can be generated by the implementation. When used with an [XML 1.0] or [HTML 4.01] application, the specifications of those languages may restrict the semantics and scope (in particular the possible target nodes) associated with an event type. Refer to the specification defining the language used in order to find those restrictions or to find event types that are not defined in this document.
The following table provides a non-normative summary of the event types defined in this specification. All event types are in no namespace and this specification refers to them by their local name only. All events will accomplish the capture and target phases, but not all of them will accomplish the bubbling phase (see also Event dispatch and DOM event flow). Some events are not cancelable (see Default actions and cancelable events). Some events will only be dispatched to a specific set of possible targets in the DOM event flow, specified using node types. Contextual information related to the event type is accessible using DOM interfaces.
| type | Bubbling phase | Cancelable | Target node types | DOM interface |
|---|---|---|---|---|
| DOMActivate | Yes | Yes | Element |
UIEvent |
| DOMFocusIn | Yes | No | Element |
UIEvent |
| DOMFocusOut | Yes | No | Element |
UIEvent |
| focus | No | No | Element |
UIEvent |
| blur | No | No | Element |
UIEvent |
| textInput | Yes | Yes | Element |
TextEvent |
| click | Yes | Yes | Element |
MouseEvent |
| dblclick | Yes | Yes | Element |
MouseEvent |
| mousedown | Yes | Yes | Element |
MouseEvent |
| mouseup | Yes | Yes | Element |
MouseEvent |
| mouseover | Yes | Yes | Element |
MouseEvent |
| mousemove | Yes | Yes | Element |
MouseEvent |
| mouseout | Yes | Yes | Element |
MouseEvent |
| keydown | Yes | Yes | Element |
KeyboardEvent |
| keyup | Yes | Yes | Element |
KeyboardEvent |
| wheel | Yes | Yes | Document, Element |
WheelEvent |
| mousewheel | Yes | Yes | Document, Element |
MouseWheelEvent |
| DOMSubtreeModified | Yes | No | Document, DocumentFragment, Element, Attr |
MutationEvent |
| DOMNodeInserted | Yes | No | Element, Attr, Text, Comment, CDATASection, DocumentType, EntityReference, ProcessingInstruction |
MutationEvent |
| DOMNodeRemoved | Yes | No | Element, Attr, Text, Comment, CDATASection, DocumentType, EntityReference, ProcessingInstruction |
MutationEvent |
| DOMNodeRemovedFromDocument | No | No | Element, Attr, Text, Comment, CDATASection, DocumentType, EntityReference, ProcessingInstruction |
MutationEvent |
| DOMNodeInsertedIntoDocument | No | No | Element, Attr, Text, Comment, CDATASection, DocumentType, EntityReference, ProcessingInstruction |
MutationEvent |
| DOMAttrModified | Yes | No | Element |
MutationEvent |
| DOMCharacterDataModified | Yes | No | Text, Comment, CDATASection, ProcessingInstruction |
MutationEvent |
| DOMElementNameChanged | Yes | No | Element |
MutationNameEvent |
| DOMAttributeNameChanged | Yes | No | Element |
MutationNameEvent |
| load | No | No | Document, Element |
Event |
| unload | No | No | Document, Element |
Event |
| abort | Yes | No | Element |
Event |
| error | Yes | No | Element |
Event |
| select | Yes | No | Element |
Event |
| change | Yes | No | Element |
Event |
| submit | Yes | Yes | Element |
Event |
| reset | Yes | Yes | Element |
Event |
| resize | Yes | No | Document, Element |
UIEvent |
| scroll | Yes | No | Document, Element |
UIEvent |
As an example, the event load will trigger event listeners attached on Element nodes for that event and on the capture and target phases. This event cannot be cancelled. If an event listener for the load event is attached to a node other than Document or Element nodes, or if it is attached to the bubbling phase only, this event listener will not be triggered.
The event objects associated with the event types described above may contain context information. Refer to the description of the DOM interfaces for further information.
The interfaces described in this section are fundamental to DOM Level 3 Events and must always be supported by the implementation. Together they define the feature Events 3.0.
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.
// Introduced in DOM Level 2: interface Event { // PhaseType const unsigned short CAPTURING_PHASE = 1; const unsigned short AT_TARGET = 2; const unsigned short BUBBLING_PHASE = 3; readonly attribute DOMString type; readonly attribute EventTarget target; readonly attribute EventTarget currentTarget; readonly attribute unsigned short eventPhase; readonly attribute boolean bubbles; readonly attribute boolean cancelable; readonly attribute DOMTimeStamp timeStamp; void stopPropagation(); void preventDefault(); void initEvent(in DOMString eventTypeArg, in boolean canBubbleArg, in boolean cancelableArg); // Introduced in DOM Level 3: readonly attribute DOMString namespaceURI; // Introduced in DOM Level 3: void stopImmediatePropagation(); // Introduced in DOM Level 3: readonly attribute boolean defaultPrevented; // Introduced in DOM Level 3: void initEventNS(in DOMString namespaceURIArg, in DOMString eventTypeArg, in boolean canBubbleArg, in boolean cancelableArg); };
An integer indicating which phase of the event flow is being processed as defined in Event dispatch and DOM event flow.
AT_TARGET
BUBBLING_PHASE
CAPTURING_PHASE
bubbles
of type boolean, readonlytrue, otherwise the value is false.
cancelable
of type boolean, readonlytrue, otherwise the value is false.
currentTarget
of type EventTarget, readonlyEventTarget whose EventListeners are currently being processed. This is particularly useful during the capture and bubbling phases. When used with the Event dispatch and DOM event flow, this attribute contains the target node or a target ancestor.
defaultPrevented
of type boolean, readonly, introduced in DOM Level 3Event.preventDefault() has been called for this event.
eventPhase
of type unsigned short, readonly
namespaceURI
of type DOMString, readonly, introduced in DOM Level 3null if it is unspecified.Event.initEvent(), set the value to null.
target
of type EventTarget, readonly
timeStamp
of type DOMTimeStamp, readonlytimeStamp may be not available for all events. When not available, the value is 0.
type
of type DOMString, readonly
initEvent
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.Event.type attribute to eventTypeArg, and Event.namespaceURI to null. To initialize an event with a namespace URI, use the Event.initEventNS() method.
eventTypeArg of type DOMStringEvent.type, the local name of the event type.canBubbleArg of type booleanEvent.bubbles. This parameter overrides the intrinsic bubbling behavior of the event.cancelableArg of type booleanEvent.cancelable. This parameter overrides the intrinsic cancelable behavior of the event.
initEventNS
introduced in DOM Level 3Event object. This method has the same behavior as Event.initEvent().
namespaceURIArg of type DOMStringEvent.namespaceURI, the namespace URI associated with this event, or null if no namespace.eventTypeArg of type DOMStringEvent.initEvent() method for a description of this parameter.canBubbleArg of type booleanEvent.initEvent() method for a description of this parameter.cancelableArg of type booleanEvent.initEvent() method for a description of this parameter.
preventDefault
Note: This method does not stop the event propagation; use Event.stopPropagation() or Event.stopImmediatePropagation() for that effect.
stopImmediatePropagation
introduced in DOM Level 3Event.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.
stopPropagation
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.
The CustomEvent interface is the recommended interface for application-specific event types. Unlike the Event interface, it allows applications to provide contextual information about the event type. Application-specific event types should have an associated namespace to avoid clashes with future general-purpose event types.
To create an instance of the CustomEvent interface, use the DocumentEvent.createEvent("CustomEvent") method call.
// Introduced in DOM Level 3: interface CustomEvent : Event { readonly attribute DOMObject detail; void initCustomEventNS(in DOMString namespaceURIArg, in DOMString typeArg, in boolean canBubbleArg, in boolean cancelableArg, in DOMObject detailArg); };
initCustomEventNS
CustomEvent object. This method has the same behavior as Event.initEventNS().
namespaceURIArg of type DOMStringEvent.initEventNS() method for a description of this parameter.typeArg of type DOMStringEvent.initEventNS() method for a description of this parameter.canBubbleArg of type booleanEvent.initEventNS() method for a description of this parameter.cancelableArg of type booleanEvent.initEventNS() method for a description of this parameter.detailArg of type DOMObjectCustomEvent.detail. This value may be null.The EventTarget interface is implemented by all the objects which could be event targets in an implementation which supports an event flow. The interface allows registration and removal of event listeners, and dispatch of events to an event target.
When used with the DOM event flow, this interface is implemented by all target nodes and target ancestors, i.e. all DOM Nodes of the tree support this interface when the implementation conforms to DOM Level 3 Events and, therefore, this interface can be obtained by using binding-specific casting methods on an instance of the Node interface.
Invoking addEventListener or addEventListenerNS repeatedly on the same EventTarget with the same values for the parameters namespaceURI, type, listener, and useCapture has no effect. Doing so does not cause the EventListener to be called more than once and does not cause a change in the triggering order.
// Introduced in DOM Level 2: interface EventTarget { void addEventListener(in DOMString type, in EventListener listener, in boolean useCapture); void removeEventListener(in DOMString type, in EventListener listener, in boolean useCapture); // Modified in DOM Level 3: boolean dispatchEvent(in Event evt) raises(EventException, DOMException); // Introduced in DOM Level 3: void addEventListenerNS(in DOMString namespaceURI, in DOMString type, in EventListener listener, in boolean useCapture); // Introduced in DOM Level 3: void removeEventListenerNS(in DOMString namespaceURI, in DOMString type, in EventListener listener, in boolean useCapture); };
addEventListener
useCapture parameter, on the capture phase of the DOM event flow or its target and bubbling phases. Invoking this method is equivalent to invoking addEventListenerNS with the same values for the parameters type, listener, and useCapture, and the value null for the parameter namespaceURI.
type of type DOMStringEvent.type associated with the event for which the user is registering.listener of type EventListenerlistener parameter takes an object implemented by the user which implements the EventListener interface and contains the method to be called when the event occurs.useCapture of type booleanuseCapture indicates that the user wishes to add the event listener for the capture phase only, i.e. this event listener will not be triggered during the target and bubbling phases. If false, the event listener will only be triggered during the target and bubbling phases.
addEventListenerNS
introduced in DOM Level 3useCapture parameter, on the capture phase of the DOM event flow or its target and bubbling phases.
namespaceURI of type DOMStringEvent.namespaceURI associated with the event for which the user is registering.type of type DOMStringEventTarget.addEventListener() method for a description of this parameter.listener of type EventListenerEventTarget.addEventListener() method for a description of this parameter.useCapture of type booleanEventTarget.addEventListener() method for a description of this parameter.
dispatchEvent
modified in DOM Level 3EventTarget object on which dispatchEvent is called.
evt of type Event|
|
Indicates whether any of the listeners which handled the event called |
|
UNSPECIFIED_EVENT_TYPE_ERR: Raised if the DISPATCH_REQUEST_ERR: Raised if the |
|
|
|
NOT_SUPPORTED_ERR: Raised if the INVALID_CHARACTER_ERR: Raised if |
removeEventListener
removeEventListener with arguments which do not identify any currently registered EventListener on the EventTarget has no effect. The Event.namespaceURI for which the user registered the event listener is implied and is null.
type of type DOMStringEvent.type for which the user registered the event listener.listener of type EventListenerEventListener to be removed.useCapture of type booleanEventListener being removed was registered for the capture phase or not. If a listener was registered twice, once for the capture phase and once for the target and bubbling phases, each must be removed separately. Removal of an event listener registered for the capture phase does not affect the same event listener registered for the target and bubbling phases, and vice versa.
removeEventListenerNS
introduced in DOM Level 3removeEventListenerNS with arguments which do not identify any currently registered EventListener on the EventTarget has no effect.
namespaceURI of type DOMStringEvent.namespaceURI associated with the event for which the user registered the event listener.type of type DOMStringEventTarget.removeEventListener() method for a description of this parameter.listener of type EventListenerEventTarget.removeEventListener() method for a description of this parameter.useCapture of type booleanEventTarget.removeEventListener() method for a description of this parameter.The EventListener interface is the primary way for handling events. Users implement the EventListener interface and register their event listener on an EventTarget. The users should also remove their EventListener from its EventTarget after they have completed using the listener.
Copying a Node, with methods such as Node.cloneNode or Range.cloneContents, must not copy the event listeners attached to it. Event listeners must be attached to the newly created Node afterwards if so desired.
Moving a Node, with methods Document.adoptNode, Node.appendChild, or Range.extractContents, shall not affect the event listeners attached to it.
// Introduced in DOM Level 2: interface EventListener { void handleEvent(in Event evt); };
Event operations may throw an EventException as specified in their method descriptions.
// Introduced in DOM Level 2: exception EventException { unsigned short code; }; // EventExceptionCode const unsigned short UNSPECIFIED_EVENT_TYPE_ERR = 0; // Introduced in DOM Level 3: const unsigned short DISPATCH_REQUEST_ERR = 1;
An integer indicating the type of error generated.
DISPATCH_REQUEST_ERR, introduced in DOM Level 3.Event object is already dispatched in the tree.UNSPECIFIED_EVENT_TYPE_ERR
Event.type was not specified by initializing the event before the method was called. Specification of the Event.type as null or an empty string will also trigger this exception.In most cases, the events dispatched by the DOM Events implementation are also created by the implementation. It is however possible to simulate events such as mouse events by creating the Event objects and dispatch them using the DOM Events implementation.
Creating Event objects that are known to the DOM Events implementation is done using DocumentEvent.createEvent(). The application must then initialize the object by calling the appropriate initialization method before invoking EventTarget.dispatchEvent(). The Event objects created must be known by the DOM Events implementation; otherwise an event exception is thrown.
The DocumentEvent interface provides a mechanism by which the user can create an Event object of a type supported by the implementation. If the feature "Events" is supported by the Document object, the DocumentEvent interface must be implemented on the same object. If the feature "+Events" is supported by the Document object, an object that supports the DocumentEvent interface must be returned by invoking the method Node.getFeature("+Events", "3.0") on the Document object.
// Introduced in DOM Level 2: interface DocumentEvent { Event createEvent(in DOMString eventType) raises(DOMException); // Introduced in DOM Level 3: boolean canDispatch(in DOMString namespaceURI, in DOMString type); };
canDispatch
introduced in DOM Level 3namespaceURI of type DOMStringEvent.namespaceURI of the event.type of type DOMStringEvent.type of the event.|
|
|
createEvent
eventType of type DOMStringThe eventType parameter specifies the name of the DOM Events interface to be supported by the created event object, e.g. "Event", "MouseEvent", "MutationEvent" and so on. If the Event is to be dispatched via the EventTarget.dispatchEvent() method the appropriate event initialization method must be called after creation in order to initialize the Event's values.
As an example, a user wishing to synthesize some kind of UIEvent would invoke DocumentEvent.createEvent("UIEvent"). The UIEvent.initUIEventNS() method could then be called on the newly created UIEvent object to set the specific type of user interface event to be dispatched, DOMActivate for example, and set its context information, e.g. UIEvent.detail in this example.
For backward compatibility reason, "UIEvents", "MouseEvents", "MutationEvents", and "HTMLEvents" feature names are valid values for the parameter eventType and represent respectively the interfaces "UIEvent", "MouseEvent", "MutationEvent", and "Event", and the characters 'a'..'z' are considered equivalent to the characters 'A'..'Z'.
|
The newly created event object. |
|
|
NOT_SUPPORTED_ERR: Raised if the implementation does not support the |
The DOM Event Model allows a DOM implementation to support multiple modules of events. The model has been designed to allow addition of new event modules if required. The DOM will not attempt to define all possible events. For purposes of interoperability, the DOM defines a module of user interface