The event module
This module presents a ‘listener-style’ interface to event handling that works in Netscape 3+, IE4+, Opera, Mozilla, Konqueror, iCab, Oregano and probably more. Naturally not all browsers will dispatch all types of events on all types of elements so it won’t automatically guarantee compatibility for you but it’s a good start.
Since version 0.8, a binding interface is also provided. You can request a function be called for every element in the document, or for each element of a certain tag name. Your function can then check each element and add listeners to it if necessary. By using bindings like this, you don’t have to worry about whether the whole document has been loaded when your script first runs.
event_addListener(source, type, listener)
Add a listener to an object. Afterwards, every time the specified event happens
on that object, your listener function will be called. type must be an
event name in a string, eg.
'click'. Adding the same
(source, type, listener) a second time has no effect, the listener
will not be called twice.
event_removeListener(source, type, listener)
Remove a listener. The function will no longer be called when the event happens. Trying to remove a listener which isn’t attached to an object has no effect. It is also safe to remove a listener from inside listener code.
Asks the event module to call the binding function back once for every element in the document that matches the selector, as soon as that element has loaded (which might be straight away). The function receives one argument, which is the element node.
selector should be a tag name, or
for all elements. On older browsers that do not support DHTML, the only
tags you can get are
'form' - any other tag names will result in
the binding function not being called. (In Netscape 4, you can also request
'div' to get layer objects.)
The listener function will be called with the arguments (source, type) when
the event occurs. If this function returns
default action is stopped - a form-submit event listener returning false will
stop the form being submitted, a link-click event listener returning false will
stop the link being followed, etc.
If there is more than one listener function and both return a value
false), the one to
be registered last will ‘win’. If a listener function returns without a value,
it does not affect whether the default action is prevented.