Your First jQuery Plugin
We all have come to love and admire jQuery for the amazing Javascript library it is. But we also have fallen in love with numerous extensions to jQuery; plugins, modules - whatever you call ‘em. Most of us, however, just use these goodies and bless the hearts of all wonderful people who make the gems available. Some of us are even a little bit intimidated when we look at all the complicated Javascript-ing going on in the source files… Especially when/if we accidentally look into a minified version ;)
Jokes aside, starting a new jQuery plugin is quite simple. Here is just how easy one could be:
(function($) {
// jQuery plugin initialization
$.fn.irakli = function(conf) {
alert("okaaaay");
};
})(jQuery);
This goofy plugin will allow you to invoke irakli() function on a jQuery object. For instance, $(‘div.something’).irakli() will have an alert box pop up.