I would add it as an option and set its default value to an empty function: var defaults = { status: '?action=live', onComplete: function() {} }
That way you could safely call onComplete when ready and it will either do nothing or call the user-supplied function. -Hector On Thu, Nov 6, 2008 at 8:33 PM, Nic Hubbard <[EMAIL PROTECTED]> wrote: > > What is the best way to add a callback to a plugin that I wrote? Do I > just add it as an additional option? > > So, after the ajax function is run, how would I allow a custom > callback or function to be added by the user? > > $.fn.testStatus = function(options) { > var defaults = { > status: '?action=live' > }; > > var options = $.extend(defaults, options); > > return this.each(function() { > > var obj = $(this); > var itemId = obj.attr('id'); > var itemHref = obj.attr('href'); > obj.click(function() { > var question = confirm('Are you sure you want change the > status?'); > if (question) { > $.ajax({ > type: 'POST', > url: itemHref + defaults.status > }); > } > return false; > }); > }); > }; >