JavaScript Document (8) Events (8) ExtJS (9) Strings (3)
Exchange Links About this site Links to us
|
Obtain the number of rows in a table
39 comments. Current rating: (9 votes). Leave comments and/ or rate it.
Question: How can I obtain the number of rows in an HTML table using javascript?
Answer: The following code assumes that your table has the ID 'MyTable'
 | |  | | <script language="JavaScript">
<!--
var oRows = document.getElementById('MyTable').getElementsByTagName('tr');
var iRowCount = oRows.length;
alert('Your table has ' + iRowCount + ' rows.');
</script>
| |  | |  |
Comments:
You are on page 1 of 3, other pages: [1] 2 3 | |
anonymous from United States
|
|
|
It is great, Thank u
|
|
anonymous from United Kingdom
|
|
|
wicked, cheers
|
|
anonymous from Sweden
|
 |
|
Simple and perfect for me today. thankyou.
|
|
anonymous from United States
|
 |
|
thank you
|
|
anonymous from Australia
|
 |
|
Just what I needed. Thanks very much.
|
|
anonymous from Mairiporã, Brazil
|
 |
|
Very simple and helful! Thanks!
In one row:
alert(document.getElementById('MyTable').getElementsByTagName('tr').length);
|
|
anonymous from Germany
|
|
|
Thanks, useful
|
|
anonymous from India
|
|
|
Thanks for your great help :)
|
|
anonymous from United States
|
 |
|
Great! Thanks. Sure beats using a SQL count...
|
2008-09-17, 03:22:27 (updated: 2008-09-17, 03:24:44) |
anonymous from Germany
|
|
|
If a html table has inner tables then the above logic does not work. Could please show to get the no of rows for outer table ? Same is true for column.
|
|
Akif from India
|
 |
|
Thnx Yaar
|
|
anonymous from United States
|
|
|
even simpler:
document.getElementById('tableid').rows.length
|
|
anonymous from United States
|
|
|
thanks, big help
|
|
|
thank you
|
2009-07-01, 02:25:29 (updated: 2009-07-01, 02:26:40) |
OPLA from Moldova
|
|
|
+1 to Karma
thank you V-E-R-YYYY much !!!
|
You are on page 1 of 3, other pages: [1] 2 3 |
|