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="" 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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.