Chapter 8. Events
By user events, I mean basically keyboard and mouse interaction like
keypress, etc. Browser
events are mainly DOM events like
window.onload, and many other events
related to DOM elements.
When coding Ajax applications, we also have custom jQuery
Ajax events that are dispatched during the process of an Ajax
request, that is,
ajaxError, and some more.
jQuery’s API is very consistent, especially when it comes to events. Attaching a handler to any kind of event is done using the same code structure:
This syntax also applies to a fourth category that I haven’t mentioned yet. jQuery’s event system can be used for event-driven programming in which you can create your own custom events that can be bound and triggered as regular ones.
jQuery also provides a shortcut method for most common browser and Ajax events. A model call using a shortcut would look like this:
eventName will be a string wrapped in either
single or double quotes. When
using the shortcut, you simply put the event’s name as the jQuery
Here’s an example of binding a click handler, with and without the shortcut: ...