开发者

adding jConfrim breaks function

开发者 https://www.devze.com 2023-01-10 18:43 出处:网络
I am trying to add a confirmation box to this code: $(\'.widget .remove\').live(\'click\', function() { //Remove wi开发者_开发知识库dget from layout

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

$('.widget .remove').live('click', function() { //Remove wi开发者_开发知识库dget 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?


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

精彩评论

暂无评论...
验证码 换一张
取 消