jQuery has convenience functions for events like click and keydown, and lets you create and use your own events with bind() and trigger(), but doesn’t provide a way to create your own convenience functions for custom events. I took several lines of code from the jQuery source and created a plugin that makes creating convenience functions as easy as calling $.convenience(‘nameOfFunction’). Then I can bind or trigger an event simply by calling nameOfFunction() on the selector. This should be apparent by looking at the demo source (the third link).
- jquery.convenience.js – plugin source (github)
- convenience.html – demo (my site)
- convenience.html – demo source (github)
The example shows one feature of custom events that I overlooked: propagation.