Reputation: 39
Here is my code, and i tried to delete one row and added a new one.It's deleting record from data base, after deleted recording I want to display remain data and remove particular row in table. but its not seems proper. please help some one
<?php for($i=0; $i<$this->labNumber; $i++):
$divlabcapdisp="divlabcap_".$i;
$divlabcoursedispdisp="divlabcoursedisp_".$i;
?>
<div class="form-group clone_field_2">
<div class="content-div">
<div class="col-sm-1">
<label class="control-label">Lab <?=$i+1?></label>
</div>
<div class="col-sm-2">
<?=$this->deliverelement($this->labElement[$i])?>
</div>
<div class="col-sm-3">
<?=$this->deliverelement($this->labtypeElement[$i])?>
</div>
<div class="col-sm-2">
<div style="display:<?php if($this->$divlabcapdisp==OT_YES):?>inline<?php else:?>none<?php endif;?>">
<?=$this->deliverelement($this->labcapElement[$i])?>
</div>
</div>
<div class="col-sm-3">
<div style="display:<?php if($this->$divlabcoursedispdisp==OT_YES):?>inline<?php else:?>none<?php endif;?>">
<?=$this->deliverelement($this->labcourseElement[$i])?>
</div>
</div>
<div class="col-sm-1 text-red" <?php if($i==0):?>style="display:none;"<?php endif;?>>
<i class="fa fa-fw fa-trash-o fa-lg" onClick="deleteButton1(this,'clone_field_2')"></i>
</div>
</div>
</div>
and the onclick function is
function deleteButton1(link,clonefield)
{
var rowCount = $('.'+clonefield).length;
var minCount = 1;
if(rowCount > minCount)
{
$(link).closest('.'+clonefield).remove();
}
else
{
alert("You cannot delete the last row");
}
}
Upvotes: 0
Views: 696
Reputation: 1382
closest() works on ancestor tree What you're looking for is parent()
Replace this
if(rowCount > minCount)
{
$(link).closest('.'+clonefield).remove();
}
with
if(rowCount > minCount)
{
$(link).parent('div').parent('div').fadeOut(200, function() { $(link).remove(); });
}
Upvotes: 1