If you’ve just started writing your fist plugin, here is the most simple boilerplate for a jQuery plugin.
Template
(function ( $ ) { $.fn.myPlugin = function(options) { //default settings var defaults = { option1: "", option2: 200, }; var settings = $.extend({}, defaults, options ); return this.each(function(){ var element = $(this); //do something to the element here }); }; }( jQuery ));
How to use the plugin
$('.any-class').myPlugin(); $('#any-id').myPlugn({option1: 'hello', option2: 1000});