tags:

views:

22

answers:

2

hi how to get with javascript the rows count of a html table having id and name.

thanks

+3  A: 

You can get it row .rows property and check it's .length, like this:

var rowCount = document.getElementById('myTableID').rows.length;
Nick Craver
I learnt something new! Thanks :)
BalusC
+3  A: 

Basically:

var rows = document.getElementById(tableId).getElementsByTagName("tr").length;

Or if there's a <tbody> in between,

var rows = document.getElementById(tableId).getElementsByTagName("tbody")[0].getElementsByTagName("tr").length;
BalusC
This would include child tables' rows in the count as well though: http://jsfiddle.net/GYstV/
Nick Craver