Chapter 4. Events are where it happens!

 

This chapter covers

  • The event models as implemented by the browsers
  • Using jQuery to bind event handlers to elements
  • The Event object instance
  • Triggering event handlers under script control

Anyone familiar with the Broadway show Cabaret, or its subsequent Hollywood film, probably remembers the song “Money Makes the World Go Around.” Although this cynical view might be applicable to the physical world, in the virtual realm of the World Wide Web, it’s events that make it all happen!

Like many other GUI management systems, the interfaces presented by HTML web pages are asynchronous and event-driven (even if the HTTP protocol used to deliver them to the browser is wholly synchronous in nature). Whether a GUI is implemented as a desktop program using Java Swing, X11, the .NET framework, or a page in a web application using HTML and JavaScript, the procedure is pretty much the same:

  1. Set up the user interface.
  2. Wait for something interesting to happen.
  3. React accordingly.
  4. Repeat.

The first step sets up the display of the user interface; the others define its behavior. In web pages, the browser handles the setup of the display in response to the markup (HTML and CSS) that we send to it. The script we include in the page defines the behavior of the interface.

4.1. Understanding the browser event models

4.2. The jQuery Event Model

4.3. Putting events (and more) to work

4.4. Summary