As a general rule, one should always define and associate event handlers as early in the document as possible. Depending on the method used, the handler can begin handling events either while the document is loading or immediately after loading.
When an event handler is set using an inline event attribute, the handler is attached when the element is created. Some events can occur while the document is loading. If one needs to handle events at this time, this method is preferred as the handler is available as soon as the object is parsed and rendered by the browser.
When an event handler is associated using the SCRIPT element's for and event attributes, the handler is attached when all the elements in the document has loaded.
Typically, event handlers are written to handle only one type of event, but it is possible to create event handlers that can handle more than one.
In general, an author can define any number of event handlers for the same type of event, and associate each handler with one or more elements in the document. Each type of event does not have to be limited to one event handler.
This is useful in cases where the action an author wants to trigger when a given event occurs in one element is different than for the same event in another element. For example:
<img src="sample.gif" onclick="flip ( )">
<button onclick="alert ( 'Hello World!' )">Try Me</button>
Note, however, that if you associate two event handlers of the same language to the same event and element, only the last handler receives the event. If you associate more than one event handler in this way and the handlers are in different languages, all handlers will receive the event, but the order in which they receive the event is not specified. For example, you can declare both a JavaScript and a VBScript event handler and associate them with the same event and element.
Also, any handler associated using the for and event attributes always takes precedence over a handler associated using an inline event attribute.