Chapter 13. Extending events
This chapter covers
- jQuery’s special event framework
- Adding a special event
- Enhancing an existing event
jQuery makes it simple to connect an event handler to one of the standard events that occur on a web page, such as mouse clicks and keystrokes. In addition to specific functions that work on collections of elements, like click and keyup, you can use the generic bind or on functions to attach a handler to a named event.
jQuery enhances the basic event handling by supporting the attachment of multiple event handlers for the same event on an element and by adding the use of namespaces to help distinguish between these event handlers. It also enables event delegation, where you can connect an event handler to a container element, but operate it on one of the contained elements, which allows you to reduce the number of registered event handlers. Additionally, event delegation gives you the ability to supply event handlers for elements that don’t exist within the DOM at the time of attachment.