overriding the default options with user-supplied options and the jQuery extend() method
eg:
$.fn.pulse = function (options) { // Merge passed options with defaults var opts = $.extend({}, $.fn.pulse.defaults, options); return this.each(function () { // Pulse for (var i = 0; i < opts.pulses; i++) { $(this).fadeTo(opts.speed, opts.fadeLow).fadeTo(opts.speed, opts.fadeHigh); } // Reset to normal $(this).fadeTo(opts.speed, 1); }); }; // Pulse plugin default options $.fn.pulse.defaults = { speed: "slow", pulses: 2, fadeLow: 0.2, fadeHigh: 1 };
call the plugin
// Override only one option $('#myText1').pulse({ pulses: 6 }); // Override all options $('#myText2').pulse({ speed: "fast", pulses: 10, fadeLow: 0.3, fadeHigh: 0.8 });