Chapter 6. Action/Reaction: Making Pages Come Alive with Events
When you hear people talk about JavaScript, you usually hear the word “interactive” somewhere in the conversation: “JavaScript lets you make interactive Web pages.” What they’re really saying is that JavaScript lets your Web pages react to something a visitor does: moving a mouse over a navigation button produces a menu of links; selecting a radio button reveals a new set of form options; clicking a form’s submit button alerts you to form fields that were left blank.
All the different visitor actions that a Web page can respond to are called events. JavaScript is an event-driven language: without events, your Web pages wouldn’t be able to respond to visitors or do anything really interesting. It’s like your desktop computer. Once you start it up in the morning, it doesn’t do you much good until you start clicking files, making menu selections, and moving your mouse around the screen.
What Are Events?
Web browsers are programmed to recognize basic actions like the page loading, someone moving a mouse, typing a key, or resizing the browser window. Each of the things that happens to a Web page is an event. To make your Web page interactive, you write programs that respond to events. In this way, you can make a <div> tag appear or disappear when a visitor clicks the mouse, a new image appear when she mouses over a link, or check the contents of a text field when she clicks a form’s Submit button.
An event represents the precise ...
Get JavaScript: The Missing Manual 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.