i.one i.one - 1 month ago 15
jQuery Question

show/hide button javascript by status

i have code like this



<script>
var a="<?php echo $data[0]->status;?>";
if(a=1){
$('#cell1').find("a").hide();
}
else if(a=2)
{
$('#cell1').find("a").show();
}

</script>

<table id="cell1" class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th> NO </th>
<th> Name</th>
<th> Status </th>
</tr>
</thead>
<tbody >
<?php $no=1; ?>
<?php foreach($data as $row):?>
<tr>
<td> <?php echo $no++;?> </td>
<td> <?php echo $row->name;?> </td>
<td> <?php echo $row->status;?></td>
<td><a href='' type="button" class="btn btn-circle blue btn-sm">View 1</a>
<a href='' type="button" name="view2" class="btn btn-circle blue btn-sm">View 2</a></td>
</tr>
</tbody>
<?php endforeach;?>
</table>





when status=1,button view 2 is hidden and vice versa.i have tried but actually all button hidden.
how to resolve it?

Answer

please update your code a little bit to

if(Number(a) === 1) {
  $('#cell1').find("a").hide();
}
else if(Number(a) === 2) {
  $('#cell1').find("a").show();
}
Comments