Table of contentsAppendices |
1.2 DOM event flowDOM event flowThe DOM event flow is the process through which the event originates from the DOM Events implementation and is dispatched into a tree. Each event has an event target, a targeted node in the case of the DOM Event flow, toward which the event is dispatched by the DOM Events implementation. Phases[top]PhasesThe event is dispatched following a path from the root of the tree to this target node. It can then be handled locally at the target node level or from any target ancestor higher in the tree. The event dispatching (also called event propagation) occurs in three phases:
NOTE: The target ancestors are determined before the initial dispatch of the event. If the target node is removed during the dispatching, or a target ancestor is added or removed, the event propagation will always be based on the target node and the target ancestors determined before the dispatch.
Some events may not necessarily accomplish the three phases of
the DOM event flow, e.g. the event could only be defined for one
or two phases. As an example, events defined in this
specification will always accomplish the capture and target
phases but some will not accomplish the bubbling phase
("bubbling events" versus "non-bubbling events", see also the
Event listeners[top]Event listenersEach node encountered during the dispatch of the event may contain event listeners. Registration of event listeners[top]Registration of event listenersEvent listeners can be registered on all nodes in the tree for a specific type of event, phase, and group. If the event listener is registered on a node while an event gets processed on this node, the event listener will not be triggered during the current phase but may be triggered during a later phase in the event flow, i.e. the bubbling phase. Event groups[top]Event groupsAn event listener is always part of a group. It is either explicitly in a group if a group has been specified at the registration or implicitly in the default group if no group has been specified. Within a group, event listeners are ordered in their order of registration. If two event listeners {A1, A2}, that are part of the same group, are registered one after the other (A1, then A2) for the same phase, the DOM event flow guarantees their triggering order (A1, then A2). If the two listeners are not part of the same group, no specification is made as to the order in which they will be triggered. NOTE: Triggering an event listener[top]Triggering an event listenerWhen the event is dispatched through the tree, from node to node, event listeners registered on the node are triggered if:
Removing an event listener[top]Removing an event listenerIf an event listener is removed from a node while an event is being processed on the node, it will not be triggered by the current actions. Once removed, the event listener is never invoked again (unless registered again for future processing). Reentrance[top]Reentrance
It is expected that actions taken by
Since implementations may have restrictions such as stack-usage or other memory requirements, applications should not depend on how many synchronous events may be triggered. Event propagation and event groups[top]Event propagation and event groupsAll event listeners are part of a group (see [Registration of event listeners]). An event listener may prevent event listeners that are part of a same group from being triggered. The effect could be:
If two event listeners are registered for two different groups, one cannot prevent the other from being triggered. |