Reputation: 145
I have this code to delete a record from a DB-ROW and delete it visually form the html-table.
$(function() {
$('.delpro').click(function(e) {
var elem = $(this);
var parents = $('.did' + elem.attr('data-id'));
$.ajax({
type: 'get',
url: 'delete.php',
data: 'id=' + elem.attr('data-id'),
beforeSend: function() {
elem.animate({ 'backgroundColor': '#fb6c6c' }, 400);
parents.animate({ 'backgroundColor': '#fb6c6c' }, 400);
},
success: function() {
parents.slideUp(300,function() {
parents.remove();
});
}
});
return false;
});
});
I need a conformation dialog before deleting. I am new to JS and JQuery. How can I do this, and where to place it inside the code?
Upvotes: 1
Views: 59
Reputation: 9060
Placing it immedietly after click :
$(function(){
$('.delpro').click(function(e){
if ( confirm('Are you sure') ) { //<--------------- here
var elem = $(this);
var parents = $('.did'+elem.attr('data-id'));
$.ajax({
type: 'get',
url: 'delete.php',
data: 'id='+elem.attr('data-id'),
beforeSend: function() {
elem.animate({'backgroundColor':'#fb6c6c'},400);
parents.animate({'backgroundColor':'#fb6c6c'},400);
},
success: function() {
parents.slideUp(300,function() {
parents.remove();
});
}
});
return false;
} //<--------------- here
});
});
Upvotes: 2