Adding an Event Handler
Answer: The old-fashioned (and still widely supported) ways of registering event handlers for page elements are:
event handler for an
by using these methods:
(in Internet Explorer 5 or newer)
(in most non-IE browsers and IE9).
The third argument
specifies that the event capturing phase should not be used, and the event should be handled during the bubbling phase of the event propagation.
You can combine the above calls together in a cross-browser function
Here is an example of calling the
function to add event handlers to two buttons with
Try adding event handlers for Button 1 and Button 2 here: If you try to register the same event handler function for the same element more than once, the results will be browser-dependent: some browsers (e.g. IE8) would repeat the same handler as many times as you registered it; other browsers (e.g. Firefox 3) would only invoke each handler function once per event.