good morning i wanna try to hide an icon using jquery in table data, if table data value reject then icon hide. but it doesnt seem right
<tr> <td id="status"><?php echo $row[PO_Status]; ?></td> <td> <center> <a id="edit" href="./page.php?page=editdatapo&id=<?php echo $row[id]; ?>"> <button type="button" class="btn btn-default btn-sm"> <span class="glyphicon glyphicon-pencil"></span> </button> </a> </center> </td> </tr>
<script> $("#status").each(function() { var status = $(this).text(); console.log(status); }); if (status = 'reject'){ $("#edit").hide(); } </script>
i have 4 td Approve,Approve,reject,reject when i check console it print Approve,Approve,Approve,Approve
Answer
As per HTML Standard you can give id only on time in a page, If there are 1 id multiple time then you have to use find.
<script> $("tr").find("#status").each(function() { var status = $(this).html(); if (status == 'reject'){ $(this).parent("tr").find("#edit").hide(); } });