Created: 2011-07-07 16:25
Updated: 2014-04-02 03:14



A boilerplate & sandbox to build & practice jQuery plugins

Best Practices

Writing jQuery plugins allows you to make the most out of the library and abstract your most clever and useful functions out into reusable code that can save you time and make your development even more efficient. Here's a brief summary of the post and what to keep in mind when developing your next jQuery plugin:

  • Always wrap your plugin in (function( $ ){ // plugin goes here })( jQuery );
  • Don't redundantly wrap the this keyword in the immediate scope of your plugin's function
  • Unless you're returning an intrinsic value from your plugin, always have your plugin's function return the this keyword to maintain chainability.
  • Rather than requiring a lengthy amount of arguments, pass your plugin settings in an object literal that can be extended over the plugin's defaults.
  • Don't clutter the jQuery.fn object with more than one namespace per plugin.
  • Always namespace your methods, events and data.
  • jQuery.fn is pronounced jQuery effin'

(used with thanks http://docs.jquery.com/Plugins/Authoring)

Further reading


- chaining & namespace examples
- demo html

- initial
Cookies help us deliver our services. By using our services, you agree to our use of cookies Learn more