I'am trying to delete a record in codeigniter using ajax call its deleting but I cant able to hide that row from table which is just deleted. Please help me out! here is my code for delete.
<script type="text/javascript">
$(document).ready(function(){
$(".delete").click(function(){
var id = $(this).attr('id');
var btn=this;
$.ajax({
type:'POST',
url:'<?=base_url()?>student/delete/',
data:'id='+id,
success:function(data) {
if(data) {
//here i want to hide that tr tag which is just got deleted
} else {
alert("no");
}
}
});
});
});
</script>
You need to use closest('tr') method, once the record from table is gets deleted just use this closest('tr') also you can animate the deletion... here is the modified code. this will do your work hope so.
<script type="text/javascript">
$(document).ready(function(){
$(".delete").click(function(){
var id = $(this).attr('id');
var btn=this;
$.ajax({
type:'POST',
url:'<?=base_url()?>student/delete/',
data:'id='+id,
success:function(data) {
if(data) {
$(btn).closest('tr').fadeOut("fast");
//or $(this).closest('tr').fadeOut("fast");
} else {
alert("no");
}
}
});
});
});
</script>
You could use $("#id-name").remove();