Home > Net >  How can I remove extra blank row from the table?
How can I remove extra blank row from the table?

Time:12-16

when I am inserting data into table it is automatically inserting one row in the bottom. How can I remove a extra blank row from the table

<table>
    <tr>
        <th>Name</th>
        <th>Comment</th>
        <th>Posted Date</th>
    </tr>
    <tr>
        <td id ="result_name"></td>
        <td id="result_comment"></td>
        <td id="posteddate"></td>
    </tr>
</table>

CodePudding user response:

Add a style with visibility:collapse

<html>
<table border="1">
    <tr>
        <th>Name</th>
        <th>Comment</th>
        <th>Posted Date</th>
    </tr>
    <tr style="visibility:collapse">
        <td id="result_name"></td>
        <td id="result_comment"></td>
        <td id="posteddate"></td>
    </tr>
</table>
</html>

CodePudding user response:

You can try to do it by using jquery:

$("td").each(function() {
    if (this.innerText === '') {
    this.closest('tr').remove();
    }
});

This function will check all the "td" and remove them if they do not have any text inside.

CodePudding user response:

You can use jQuery function to check the data is empty or not.

$("td").each(function() {
    if (this.innerText === '') {
    this.closest('tr').remove();
    }
});

    <table>
    <tr>
        <th>Name</th>
        <th>Comment</th>
        <th>Posted Date</th>
    </tr>
    <tr>
        <td id ="result_name"></td>
        <td id="result_comment"></td>
        <td id="posteddate"></td>
    </tr>
</table>

  • Related