<table id='t'>
<tr>
<td id='foo' class='a b c'>blah</td>
<td id='bar' class='a c'>bloo</td>
<td id='zip' class='a b c'>blop</td>
</tr>
</table>
Using jQuery, why does the following children
call return 0
$('#t').children('tr').length
but find
returns 1?
$('#t').find('tr').length
https://jsfiddle.net/o71x6co6/1/
Because browsers automatically add a tbody
element if you don't.
console.log($('#t').children().get(0).tagName);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table id='t'>
<tr>
<td id='foo' class='a b c'>blah</td>
<td id='bar' class='a c'>bloo</td>
<td id='zip' class='a b c'>blop</td>
</tr>
</table>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With