Reputation: 37
I need to hide a table if td is empty (without a
and div's
).
sorry guys, my bad
if there is content, there is nothing to hide do not need but if td is empty - need to hide the table
<table class="klist-actions">
<tr>
<td class="klist-actions-goto">
<a name="forumbottom"></a>
</td>
<td class="klist-actions-forum">
<div class="kmessage-buttons-row">
<a class="kicon-button kbuttoncomm btn-left" href="#"></a>
</div>
</td>
<td class="klist-pages-all">
</td>
</tr>
</table>
Upvotes: 1
Views: 427
Reputation: 37
thx friends ! this code works !!!
$('table').filter(function() {
var $tds = $('td', this);
return $tds.filter(function() {
return $.trim(this.innerHTML).length === 0;
}).length === $tds.length;
}).hide();
Upvotes: 0
Reputation: 144689
If you want to hide tables that have empty td
elements you can use .filter()
method:
$('table').filter(function(){
return $('td', this).filter(function() {
return $.trim(this.innerHTML).length === 0;
}).length;
}).hide();
In case that you want to hide the table that all of it's td
descendants are empty, you can compare the length of the td
descendants with empty ones, if all of them are empty hide the table:
$('table').filter(function() {
var $tds = $('td', this);
return $tds.filter(function() {
return $.trim(this.innerHTML).length === 0;
}).length === $tds.length;
}).hide();
Upvotes: 1
Reputation: 94469
This code will hide the table if any of the td
elements are empty:
//select all td elements, iterate through them and check the length of their content
$(".klist-actions td").each(function(i,e){
if(!$.trim(e.innerHTML).length){
$(e).parents("table").hide();
}
});
JS Fiddle: http://jsfiddle.net/XJd8t/7/
Upvotes: 4
Reputation: 5647
The code below will hide any 'table' that has at least one 'td' that doesn't have either an 'a' or 'div'
$('table:has(td:not(:has(a div)))').hide();
jQuery has a lot of interesting selectors, read about them here
Upvotes: 0