Is it possible to change the css
using jquery
if there are no rows in the table body? I have attempted this but my current approach is not working. I tried adding an alert
within the if
statement, but the alert did not appear. My goal is to hide the table
if the tbody
does not contain any tr
.
$(document).ready(function() {
var tbody = $(".table-condensed tbody");
if (tbody.children().length == 0) {
$(".blankdata").css("display", "none");
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table class="table table-bordered table-condensed">
<thead>
<tr>
<th class="text-center blankdata">EMPLOYEE NAME</th>
<th class="text-center blankdata">DESCRIPTION</th>
<th class="text-center blankdata"># of Payments</th>
<th class="text-center blankdata">LOAN AMOUNT</th>
<th class="text-center blankdata">TOTAL PAYMENT</th>
<th class="text-center blankdata">BALANCE</th>
<th></th>
</tr>
</thead>
<tbody class="table-warehouse">
<tr id="blank">
<td class="text-center blankdata"></td>
<td class="text-center blankdata"></td>
<td class="text-center blankdata"></td>
<td class="text-center blankdata"></td>
<td class="text-center blankdata"></td>
<td class="text-center blankdata"></td>
<td class="text-center"></td>
</tr>
</tbody>
</table>