JavaScript Resources

Event Handlers

When an event occurs, JavaScript can react. This reaction is facilitated through what are known as event handlers. There are several ways to handle events in JavaScript.

One way is inside of html tags. Many events are associated with a corresponding html tag or set of tags, and can be placed inside of these tags as attributes. When this is the case, the event handler is considered the keyword of the attribute, and the JavaScript statements to execute are the value.

For example:

    <img src="smiley.gif" onClick="alert('Hey!')" />

Event handlers via html attributes present a second way in which to insert a script. When you use an event handler to inititate a script, you do not need to identify the script to the browser with a set of <SCRIPT> tags. They also provide a bit of a control lever: the script will only execute when it is triggered by the event.

Next up ... use of quotes in event handlers