Reputation: 55
hide the column which it is in. I have created.
My table is below;
<table id="tester" border='1'>
<tbody>
<tr>
<td>test1</td>
<td>test2</td>
<td>test3</td>
</tr>
<tr>
<td>test1</td>
<td></td>
<td>test3</td>
</tr>
<tr>
<td>test1</td>
<td>test2</td>
<td>test3</td>
</tr>
<tr>
<td>test1</td>
<td>test2</td>
<td>test3</td>
</tr>
<tr>
<td>test1</td>
<td>test2</td>
<td>test3</td>
</tr>
</tbody>
</table>
And the Jquery I am trying to get working is below;
Any help would be appreciated.
Upvotes: 0
Views: 111
Reputation: 12974
To hide the whole column if one of its cells is empty, use this:
$.each($('td:empty'), function(){
$('td:nth-child(' + ($(this).index() + 1) + ')').hide();
});
Upvotes: 0
Reputation: 5055
I think that youre looking for.
$.each($('table > tbody > tr'), function(){
if($(this).find('td:empty').length>0){
// You can hide
$(this).hide();
// Or Remove
$(this).remove();
// Or Fadeout and remove
$(this).fadeOut(250, function(){$(this).remove();});
}
});
Upvotes: 0
Reputation: 8343
Try this:
function hidecol2() {
var cell = $('#tester > tbody > tr:eq(1) > td:eq(1)');
if (cell.text() == '') cell.parent().parent().children().children(':nth-child(2)').hide;
};
Upvotes: 1