Converting Your Scripts Into a jQuery Plugin

We feature a lot of plugins on this site, so chances are if you're looking for a particular type of plugin, you'll be able to find that here. Just in case, the following is some code that will help you convert your jQuery scripts into a plugin that can be used by other developers on other sites and projects. If you spend a lot of time writing a particular script to create a functionality, it's definitely worth it to convert that code into a plugin, either for your own future use, for the future use of others, or both.

The basic code to create a plugin is actually very straightforward. Really, all you have to do is create a $.fn object and extend it with your own custom function. Check out the code below:

(function($){ $.fn.yourCustomPluginName = function(){ // insert your script here return this; }; })(jQuery);

As you can see, it only takes a few extra lines of code to create your own unique jQuery plugin. When converting your own code into a plugin, make sure your code is clean, organized, and well documented (especially if you intend to make it available for the use of other developers).

Nothing shocks me, I'm a Software Engineer. And I am not young enough to know everything. I live in World Wide Web and from there take care of this website. This website communicates about my work, learning and experience. I believe life is short, and it is for loving, sharing, learning and connecting. So lets connect..