I have this table:
while ($row = mysqli_fetch_array($result)) {
echo '<tr>';
echo '<td> <button value="' . $row['id'] . '" class="btn btn-danger" id="delete"><i class="icon-remove icon-white"></i> Delete</button> </td>';
echo '</tr>';
}
which result in this:
I'm using this javascript to delete specific row:
<script type="text/javascript">
$('.btn-danger').click(function() {
alert("I am an alert box!");
var one = $(this).val();
$.post("post.php", {
id: one
}, function(data) {
if (data.response == 1) {
$(this).closest('tr').fadeOut(1000); //this line does not work
}
if (data.response == 0) {
alert("nope");
}
}, "json");
});
</script>
The fade out does not work. No fade happen. I'm not sure whats wrong but if I use id
it's will worked. $('#delete').closest('tr').fadeOut(1000);
but the problem is only top row will fade out and I dont want to use id
. I'm doing my research about class but I still couldn't understand how to get this to work.
Please help me and thanks in advance.