javascript - jquery custom div to confirm delete action -


i have jquery delete customer comment.

my problem in "if(confirm" part. want show div asking if user sure deleting comment. not browser default alert box.

how can this?

var progressajax = false;  $(document).ready(function() { $(".delete_post").on('click',function(){                         if(progressajax) return;                        progressajax = true;  var element = $(this); var = element.attr("id");  if(confirm('are sure?')){  $.ajax({    type: "post",    url: "/js-calls/post_delete.php",    data: "id="+i,    success: function(){             progressajax = false;     $(".volta"+i).fadeout(600, function(){      $(".volta"+i).remove();     });    }  }); } return false; }); }); 

and there can improve here? thanks

one simple solution utilize jquery .hide() , .show() hide/show div element when need to. enhance leverage bootstrap mentioned above make more of visually appealing modal dialog, should give idea of how code should work.

html

<!doctype html /> <html>     <head>         <title></title>     </head>     <body>         <input type="button" value="delete item" id="btndelete"/>         <div id="confirmbox">             <p>are sure want delete record?</p>             <br />             <input type="button" value="yes" id="btnyes"/>             <input type="button" value="no" id="btnno" />         </div>         <script type="text/javascript" src="jquery_v1.10.2.js"></script>         <script type="text/javascript" src="thejs.js"></script>     </body> </html> 

javascript

$(document).ready(function () {     $('#confirmbox').hide();      $('#btndelete').on('click', function (e) {         $('#confirmbox').show();     });      $('#btnyes').on('click', function (e) {         //do delete action here         alert("item deleted");         $('#confirmbox').hide();     });      $('#btnno').on('click', function (e) {         //cancel action here         alert("action cancelled");         $('#confirmbox').hide();     });  });