Chapter 9Plugins

Beyond making many scripting tasks much easier, jQuery also makes itself easy to extend with new functionality. This is done with an easy-to-understand Plugin API. Using jQuery's Plugin API, you can make your own chainable jQuery methods and even write entire complex client-side applications completely as jQuery plugins.

There are a lot of things you can do with plugins. Some of the more useful and prominent examples of jQuery plugins are found in the jQuery UI library, which I discuss in more detail in Chapter 12, “Draggable and Droppable.” Plugins in the jQuery UI library help you to implement functionality like drag-and-drop or selecting elements, and a variety of other functionality. There is also a thriving third-party development community for jQuery that produces plugins for just about anything you can think of. You'll examine a few third-party jQuery plugins and even write one in Part II, “jQuery UI,” of this book. jQuery's thriving plugin community exists largely thanks to how ridiculously easy it is to write plugins for jQuery.

This chapter demonstrates how to use jQuery's Plugin API and covers the basic concepts you need to understand to start writing plugins of your own. Beyond what you learn about jQuery plugin basics in this chapter, you also see more examples that use jQuery's Plugin API later in the book.

Writing a Plugin

jQuery plugins are easy to implement. All you need to do is pass an object literal containing the methods you want to extend ...

Get Web 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.