views:

13

answers:

1

I am trying to add a confirmation box to this code:

$('.widget .remove').live('click', function() { //Remove widget from layout
  $(this).closest('.widget').fadeOut('fast', function() {
    $(this).remove();
    saveLayout(false);
  });
  return false;
});

This is what I did:

$('.widget .remove').live('click', function() { //Remove widget from layout
jConfirm('Are you sure you want to remove this widget?','Are you sure?',function(r){
  if(r)
  {
      $(this).closest('.widget').fadeOut('fast', function() {
        $(this).remove();
        saveLayout(false);
      });
      return false;
  }
  });
});

Before I started mucking with it, the removal function worked great, now it doesn't do anything. I know the if(r) is getting executed because I put test alert("messages") in the code when I was testing it. I dont know enough about jquery (or java script for that matter) to know what is going wrong. Help?

+1  A: 

the this in the main function was different from the this in jConfirm.

 var $this=$(this);

and then replacing every (this) in the jConfirm solved it

0_o