delete table empty row

by oterox

HTML

<table id="mytable" border="1">  
    <tr><th>Column1</th><th>Column2</th><th>Column3</th><th>Column4</th></tr>
    <tr class="data"><td>1st</td><td>1.1</td><td></td><td>1</td></tr>
    <tr class="data"><td>2nd</td><td>2.01</td><td></td><td>2</td></tr>  
    <tr class="data"><td>3rd</td><td>3.001</td><td></td><td>3</td></tr>  
    <tr class="data"><td>4th</td><td>4.01</td><td></td><td>4</td></tr>
</table>

JavaScript

$('#mytable th').each(function(i) {
    var remove = 0;

    var tds = $(this).parents('table').find('tr td:nth-child(' + (i + 1) + ')')
    tds.each(function(j) { if (this.innerHTML == '') remove++; });

    if (remove == ($('#mytable tr').length - 1)) {
        $(this).hide();
        tds.hide();
    }
});