O'Reilly logo

Microsoft Visual Studio 2015 Unleashed, Third Edition by Mike Snell, Lars Powers

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Events

JavaScript is used to run client code in the browser as a reaction to a user taking action or something on the page happening. These actions are triggered events to which you can subscribe by writing event-handling functions. There are dozens of events, such as the page loading, the user clicking a button, the Tab key being pressed, a hyperlink being selected, and the browser being resized.

Events are based on a publisher-subscriber pattern. Objects already expose events that will be triggered when certain things happen. You can then write code to subscribe to these events. In doing so, your code will then be called when the event bubbles up.

Let’s take a look at an example. Imagine that you have the markup shown in Listing 18.2. This ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required