Check out a free preview of the full jQuery Plugins and jQuery UI course:
The "Plugins & State" Lesson is part of the full, jQuery Plugins and jQuery UI course featured in this preview video. Here's what you'd learn in this lesson:

Most plugins don’t contain state. jQuery changed how we interact with the DOM by easily chaining several tasks together to create more complex tasks. Example is a notification system chaining four simple elements to create one task. Without querying the DOM, though, you cannot know the state. Another example is using ajax and progressive enhancement to create a complex task, though you still don’t know the state of the plugin. Can you build a stateful plugin in jQuery Core? Yes. API for ajax reveals object state and allows you to embed callbacks to alert you when something happens; however, it’s not a jQuery plugin. Use the ajax API to mimic the plugin to get the “state” of your plugin, but you must manage it by initializing it, and the calls, after initialization. Define a new API for how plugins work in state - Option 1 Use multiple functions on $.fn. - easy to understand, but can become lengthy. Option 2 Use prefixes for method names, making it a little more streamlined and “categorized,” and names more searchable. Option 3 Return the plugin instance. Not the best idea as it breaks chaining, works on one element and method is ambiguous. Option 4 Use a single method that proxies to other methods. Downside is this can look a little strange to users. The number one aim is to not pollute jQuery. Accomplish this by using the jQuery UI API.

Get Unlimited Access Now