Living documents with XML events (2/4) - exploring XML | WebReference

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.
capture
Listener is activated during capturing phase.
default
Listener is activated during bubbling or target phase.

The default behavior is phase="default".

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).
stop
event propagation stops
continue
event propagation continues (unless stopped by other means, such as scripting, or by another listener).

The default behavior is propagate="continue".

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.
cancel
if the event type is cancellable, the default action is cancelled
perform
the default action is performed (unless cancelled by other means, such as scripting, or by another listener).

The default value is defaultAction="perform".

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