Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using JQuery to remove blank rows from HTML Tables

I have an HTML table:

<table id="indicationResults" class="resultsGrid" cellpadding="2" cellspacing="0" >

Some of the cells in the table only contain strings depending on specific permissions. For example, here is one row that only puts a label and data in each cell if the user has a specific permission:

<tr>
    <td id="DV01Label" class="resultsCell">
        <%= CustomHelpers.StringWithPermission("DV01", new string[] { PERMISSIONS.hasALM })%>
    </td>
    <td id="DV01Value" class="alignRight">
        <%= CustomHelpers.StringWithPermission(Model.Results.DV01.ToString(Chatham.Web.Data.Constants.Format.CurrencyCentsIncludedFormatString), new string[] { PERMISSIONS.hasALM })%>
    </td>
    <td id="DV01Fixed" class="alignRight">
        <%= CustomHelpers.StringWithPermission(Model.Results.FixedComponent().DV01.ToString(Chatham.Web.Data.Constants.Format.CurrencyCentsIncludedFormatString), new string[] {PERMISSIONS.hasALM})%>
    </td>
    <td id="DV01Floating" class="alignRight">
        <%= CustomHelpers.StringWithPermission(Model.Results.FloatingComponent().DV01.ToString(Chatham.Web.Data.Constants.Format.CurrencyCentsIncludedFormatString), new string[] { PERMISSIONS.hasALM })%>
    </td>
</tr>

How do I go back through and delete and all completely empty rows in this SPECIFIC table after the page loads using JQuery, so instead of seeing a tiny little empty row, it's just not there.

like image 492
slandau Avatar asked Nov 27 '25 19:11

slandau


1 Answers

With jQuery:

$('#indicationResults tr').each(function () {
     if (!$.trim($(this).text())) $(this).remove();
});

Although it would be much better if you could modify your asp to only output rows when the user has the right permissions ;)

like image 115
David Tang Avatar answered Nov 30 '25 09:11

David Tang



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!