Event.observe is a cross-browser compatible function to define event handlers programmatically. It also provides automatic clean-up of the event handlers when the page is unloaded, this prevents memory leaks in Internet Explorer and Gecko-based browsers.
The observer function receives the event object as its argument, thus negating the need to use ‘window.event’ on IE.
To stop observing events, call Event.stopObserving.
(todo)
Event.observe(element, name, observer, [useCapture]);
For more information on useCapture, see http://www.mozilla.org/docs/dom/domref/dom_el_ref31.html
<h2 id="mydiv">Click me!</h2>
<script type="text/javascript" language="javascript">
Event.observe('mydiv', 'click', function(e){ alert('clicked me!') });
</script>
Note that the script tag is placed AFTER the observed element, and that only the first element with the given id will be observed even if you have many element with the same id attributes. (w3c recommend that every id have to be unique so guess this is a correct behaviour).
creates: