Chapter 3. Events

One of John Resig's primary motivations for creating jQuery was the need to make support for certain scripting features more seamless across browsers in a way that is as efficient and performance-aware as is possible. John has managed pretty well — his Event API not only works across all the popular, modern browsers, but it also simplifies events in very intuitive ways, reducing the amount of code that you need to write to bind events to objects.

That said, to truly appreciate what John has done to bridge the gap in jQuery, a brief review of how events work without a framework is in order. This chapter reiterates how event handling works in JavaScript via the traditional event model, the W3C event model, and Microsoft's JScript event model, followed by a demonstration of how events work with jQuery.

Long a thorn in the sides of web developers everywhere is the rift in the event model supported by Internet Explorer, and the event model standardized by the W3C. Over the years, developers have come up with all sorts of creative ways to unite these different event models to have an extensible, reliable, and easy-to-use Event API. To truly understand the challenge that a developer faces when attempting to bridge the compatibility gaps in event handling, you have to understand the subtle nuisances that created the compatibility gap in the first place. In this chapter, I look at the different methods for attaching an event in more detail by providing a recap on how each ...

Get Beginning JavaScript® and CSS Development with jQuery 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.