Count of td (table) using jQuery?
<table>
<tbody>
<tr class="row-1 row-first">
<td><div class="inside">Text</div><开发者_如何转开发/td>
<td><div class="inside">Text</div></td>
<td><div class="inside">Text</div></td>
</tr>
<tr class="row-2">
<td><div class="inside"></div></td>
<td><div class="inside">Text</div></td>
<td><div class="inside">Text</div></td>
</tr>
<tr class="row-3 row-last">
<td><div class="inside"></div></td>
<td><div class="inside">Text</div></td>
<td><div class="inside">Text</div></td>
</tr>
</tbody>
</table>
That is my HTML.. I want to know the count of td's which does not have an empty div (with class="inside") in jQuery? How do I go about it?
Something like this, with the has
, not
, and empty
selectors:
$('td:not(:has(div.inside:empty))').length;
Made a shorter version:
$("td div.inside:not(:empty)").length;
example here: http://jsfiddle.net/j7ucY/1/
$('td div.inside').filter(function(idx){
return $(this).text() != ""
}).length;
demo
精彩评论