Living documents with XML events (2/4) - exploring XML
Living documents with XML events
Easy listening
Element listener
is used to declare event listeners and
register them with specific nodes in the DOM. It has the following
attributes:
event | the event type for which the listener is being registered. |
observer | optional, the id
of the element with which the event listener is to be registered. By default
the observer is the element that the
event attribute is on.
|
target | optional, the id
of the target element of the event (i.e., the node that caused the event). If
present, only events that match both the event
and target attributes will be processed by the associated event
handler.
|
handler | optional, the URI of an element that defines the action that should be performed if the event reaches the observer. This specification does not mandate what form that element should take. |
phase | optional, during which DOM
2 event propagation phase the listener will be activated by the desired
event.
The default behavior is Note that not all events bubble, in which case with phase="default" you can only handle the event by making the event's target the observer. |
propagate | optional, whether after
processing all listeners at the current node, the event is allowed to continue
on its path (either in the capture or the bubble phase).
The default behavior is |
defaultAction | optional, if after
processing of all listeners for the event at the current element, the default
action for the event (if any) should be performed or not. For instance, the
default action for a mouse click on an <a> element in XHTML
is to traverse the link. Note that this is only useful when the observer is
the <a> element, and not some parent element.
The default value is Note that not all events are cancellable, in which case this attribute is ignored. |
id | optional, a document-unique identifier. The value of this identifier is often used to manipulate the element through a DOM interface. |
A listener example
This example attaches the handler in the element at "#click"
that will get activated when the event called activate
occurs on
the element with id="button1"
, or any of its children. The
activation will occur during bubbling, or if the event happened on the
observer element itself, when the event reaches the element (phase
target).
<listener event="activate" observer="button1" handler="#click"/>
Events can be attached to different elements
Produced by Michael Claßen
URL: https://www.webreference.com/xml/column43/2.html
Created: Nov 12, 2001
Revised: Nov 12, 2001