CHAPTER 11

image

Events

Events are occurrences that take place in the interaction between the user, the web page, and the browser. Event handling enables a script to detect and react to these occurrences, allowing the web page to become interactive.

Event Handling

There are three steps to handling an event. First, you need to locate the element that will receive the event. Events always take place in the context of element nodes inside the DOM tree. In this example the event will occur when the following hyperlink is clicked.

<a href="http://www.google.com" id="mylink">My link</a>

The next step is to create an event handler, which is the code that will ...

Get JavaScript Quick Syntax Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.