EVENT HANDLERS
Events are certain actions performed either by the user or by the browser itself. These events have names like click
, load
, and mouseover
. A function that is called in response to an event is called an event handler (or an event listener). Event handlers have names beginning with "on"
, so an event handler for the click
event is called onclick
and an event handler for the load
event is called onload
. Assigning event handlers can be accomplished in a number of different ways.
HTML Event Handlers
Each event supported by a particular element can be assigned using an HTML attribute with the name of the event handler. The value of the attribute should be some JavaScript code to execute. For example, to execute some JavaScript when a button is clicked, you can use the following:
<input type="button" value="Click Me" onclick="console.log('Clicked')"/>
When this button is clicked, a message is logged. This interaction is...