JQuery offers a very practical and easy way to build plugins, as well as a very good documentation on this subject. However, it could be useful to see how a plugin is written step-by-step.
Basic Structure
The basis of creating a plugin for jQuery is actually quite simple. You don't have to be a jQuery ninja, nor do you have to sweat blood to make it work. It's as easy as script writing!
Following the jQuery plugin authoring guidelines is a good idea. Bear in mind that 1) plugins files should be named jquery.PLUGINNAME.js and 2) always attach your plugins to jQuery instead of $, so aliases can be easily set using the noConflict() method.
The structure required to extend the jQuery.fn object is…
jQuery.fn.firstPlugin = function () { return this.each (function () { alert (this.id); }); } |