Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery, Using .remove() , but I would like a confirmation box to appear

I am using jQuery's .remove() to get rid of divs of content, but I would like to be able to have a confirmation or dialog box appear before it is removed. I am just not sure of the context of how I would write such a dialog.

$(".remove").click(function () {
  $('div').remove('#item1');
});

Upon clicking the link with class remove I would like a box to popup saying Are you sure you want to remove this? Then click Yes to remove and no to keep it. Thanks in Advance

like image 591
CarterMan Avatar asked Dec 02 '22 05:12

CarterMan


2 Answers

$(".remove").click(function () {
  if(confirm("Are you sure you want to remove this?")) {
    $('div').remove('#item1');
  }
});
like image 68
Marc Gravell Avatar answered Dec 03 '22 23:12

Marc Gravell


Try this:

$(".remove").click(function () {
  if(confirm("are you sure you want to remove the div")){
    $('div').remove('#item1');
  }
});

Hope it helps

like image 43
sTodorov Avatar answered Dec 03 '22 23:12

sTodorov