Reputation: 6762
I am trying to hide table row if that rows td has no text inside it. How to do that. So far i tried is at fiddle here
Javascript:
$('#tblNodes > tbody > tr').each(function () {
if ($td.text() == '') {
$(this).hide();
}
});
HTML:
<table id="tblNodes" border=1 width=100%>
<tr>
<td class="nodeData"></td>
</tr>
<tr>
<td class="nodeData">abc</td>
</tr>
<tr>
<td class="nodeData"></td>
<tr>
<td class="nodeData"></td>
</tr>
<tr>
<td class="nodeData">abc</td>
</tr>
<tr>
<td class="nodeData"></td>
</tr>
</tr>
</table>
Upvotes: 2
Views: 12313
Reputation: 388316
Try
$('#tblNodes > tbody > tr').has('td:empty').hide()
or
$('#tblNodes > tbody > tr td:empty').parent().hide()
Upvotes: 5
Reputation: 3559
Try this:
$('#tblNodes tbody tr').each(function () {
if ($(this).find('td').is(':empty')) {
$(this).hide();
}
});
Upvotes: 1
Reputation: 11693
You can try :
1)Check for TD in each TR in table.
2)If it has no text , set its display property to none.
$('#tblNodes tr').each(function() {
$td=$(this).find('td');
if($td.text() === ''){
$(this).css("display", "none");
}
});
Upvotes: 1
Reputation: 7079
Try this
$('#tblNodes > tbody > tr').each(function() {
if($(this).find('td').text() == ''){
$(this).hide();
}
});
Upvotes: 1
Reputation: 36531
try this
$('#tblNodes tr').each(function() {
$td=$(this).find('td');
if($td.text() == ''){
$(this).hide();
}
});
Upvotes: 1
Reputation: 67207
You can use .is()
along with :empty
selector to achieve what you want.
Try,
$('#tblNodes > tbody > tr').each(function () {
if ($(this).find('td').is(':empty')) {
$(this).hide();
}
});
Upvotes: 2