The addEventListener() method will attach a function object to an EventTarget node in such a way that the function is called when the event is triggered. An Event object is passed to the function as an argument so you need to specify this in its declaration. This is how handler functions are registered as listeners.
You can replace a listener with another by registering a new listener with the same parameters. The old one will be discarded. If you want to stop the listener from responding to the event, you can deregister it with the removeEventListener() method.
The three parameters to the addEventListener() method are:
A string describing the event type being registered.
A reference to a function object that has been declared elsewhere in the script source text.
A Boolean flag value that indicates whether the event listener should use bubbling (bottom up) or capture (top down) event propagation. Both types can be registered separately but must also be removed separately.
Examining the DOM level 2 specification suggests that these event type strings may be used:
|Event string||Event object type||DOM|
Note that the DOM level 2 event module specification is somewhat ambiguous on the specifics of event type values and you may want to refer to the specification if you are intending to exercise these capabilities in the Netscape Navigator version 6.0 browser. This functionality is fairly new and still in a state of evolution but since it is defined in a standard, it will become more widespread and is therefore the best way to ensure portability even if it takes a while for the various browser manufacturers to catch up and make their products compliant.