Chapter 2. A first plugin
This chapter covers
- The jQuery architecture
- Creating a simple collection plugin
jQuery is a JavaScript library that makes it much simpler to interact with the elements on a web page. It’s typically used by finding elements of interest, either by direct selection or by traversing the DOM, then applying some functionality to those elements. You can manipulate elements—adding or removing them, or changing their attributes and properties—and add event handlers to them to respond to actions from the user. You can animate elements by changing their properties over time. And jQuery lets you use Ajax to request extra information from the server easily, without disrupting the current page and its contents.
In the previous chapter, I mentioned that jQuery can’t do everything, so it offers a number of extension or integration points, which has led to a thriving third-party plugin community.
This chapter looks at the jQuery architecture that allows plugins to operate alongside the built-in code, and then presents a simple collection plugin (one that operates on a set of selected elements) to show what can be done. The remaining chapters examine each extension point in detail, explain how to use them to enhance jQuery’s abilities, and present a set of guiding principles and best practices for developing your plugins.