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?