I have seen several examples on how to find children, etc but for some reason I can't get this one right ... any help from the SO community?
The below is my current "attempt" in code --
var trCount = $("#table > tr").size();
This should work:
var count = $("#table tr").length;
Plain Old DOM:
document.getElementById('table').rows.length;
is going to be much more efficient than asking jQuery to go work out the selector and return every row element for you.
You don't have to force everything you do into a jQuery-shaped hole; sometimes the old ways are still the best. jQuery was created to supplement JavaScript in the areas it was weak, not completely replace the entire language.
$("#table tr").size();
Fails for nested tables.
$("#table > tr").size();
Fails for tr in tbody (which is very often the case as they can get inserted automatically).
$("#table > tbody > tr").size();
Fails for tr in thead/tfoot.
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