© Mark J. Collins 2017

Mark J.  Collins, Pro HTML5 with CSS, JavaScript, and Multimedia, 10.1007/978-1-4842-2463-2_20

20. Events

Mark J. Collins

(1)Chesterfield, Virginia, USA

Events are an integral part of most web pages: they allow you to take an action when something happens. The “something happens” is called an event, and there are dozens of them that have been defined in the web standard (see http://www.w3.org/TR/DOM-Level-3-Events/#events-module ). The “an action” is called an event handler, which is just a simple JavaScript function.

Initial Example

I'll start with a simple example and then describe the pieces. A basic HTML document is shown in Listing 20-1.

Listing 20-1. The initial HTML document
<!DOCTYPE html><html lang="en">    <head> ...

Get Pro HTML5 with CSS, JavaScript, and Multimedia: Complete Website Development and Best Practices 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.