If you want to pass it in as a parameter, yes. If you want it accessible as the "this" variable, you should be able to achieve that using .apply
I threw a pretty straightforward test up on jsbin: http://jsbin.com/ecina/edit Apply lets you change the scoping of your object, which is how you can call it without passing variables like jQuery does for a number of functions (like $.each) On Feb 25, 4:07 pm, brian <[email protected]> wrote: > You need to specify what you'll be passing to the onComplete function. > > $('a.matrixStatus').matrixStatus({ > urlSuffix: '?action=status_posting', > onComplete: function(el) {alert('Callback worked'); > alert(el.attr('class'));} > > }); > > obj.click(function() { > var self = $(this); > > ... > > defaults.onComplete(self); > > On Wed, Feb 25, 2009 at 3:52 PM, Nic Hubbard <[email protected]> wrote: > > > I was meaning when trying to call $(this) in the following > > circumstance: > > > $('a.matrixStatus').matrixStatus({ > > urlSuffix: '?action=status_posting', > > onComplete: function() {alert('Callback worked'); alert($ > > (this).attr('class'));} > > }); > > > When I am trying to pass things to the custom function, using $(this) > > does not work. > > > On Feb 25, 12:28 pm, brian <[email protected]> wrote: > >> Something like this? (no pun intended) > > >> obj.click(function() { > >> var self = $(this); > > >> ... > > >> defaults.onComplete(self); > > >> On Wed, Feb 25, 2009 at 3:11 PM, Nic Hubbard <[email protected]> wrote: > > >> > I have built a custom callback into my plugin, here is an example: > > >> > $.fn.matrixStatus = function(options) { > >> > var defaults = { > >> > urlSuffix: '?action=live', > >> > onComplete: function() {} > >> > }; > > >> > var options = $.extend(defaults, options); > > >> > return this.each(function() { > >> > var obj = $(this); > >> > var itemDesc = obj.attr('rel'); > >> > var itemId = obj.attr('id'); > >> > var itemHref = obj.attr('href'); > >> > obj.click(function() { > >> > if (!itemDesc == '') { > >> > var question = confirm('Are you sure you want to change > >> > the status > >> > of "'+itemDesc+'"?'); > >> > } else { > >> > var question = confirm('Are you sure you want to change > >> > the > >> > status?'); > >> > } > >> > if (question) { > >> > $.ajax({ > >> > type: 'POST', > >> > url: itemHref + defaults.urlSuffix > >> > }); > > >> > // Run our custom callback > >> > defaults.onComplete(); > > >> > } > >> > return false; > > >> > }); > > >> > }); > > >> > }; > > >> > For some reason when I try to use that function for a custom callback, > >> > it won't allow me to get the jQuery object that the plugin is > >> > targeting, so using $(this) within the onComplete function doesn't > >> > work and give me errors. Any idea why this would be?

