function(id){ alert(MyId); swal("Deleted!", "Your imaginary file has been deleted.", "success"); });
This will not work, because in this case id isConfirm option for your confirmation dialog box - see SweetAlert Documentation .
This will work - no additional variable is needed:
function foo(id) { swal({ title: "Are you sure?", text: "You will not be able to recover this imaginary file!", type: "warning", showCancelButton: true, confirmButtonColor: "#DD6B55", confirmButtonText: "Yes, delete it!", closeOnConfirm: false }, function(isConfirm){ alert(isConfirm); alert(id); swal("Deleted!", "Your imaginary file has been deleted.", "success"); }); } foo(10);
here's jsfiddle: http://jsfiddle.net/60bLyy2k/
source share