DelphiFAQ Home Search:

Obtain the number of rows in a table


comments52 comments. Current rating: 4 stars (22 votes). Leave comments and/ or rate it.


How can I obtain the number of rows in an HTML table using javascript?


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.');


You are on page 1 of 4, other pages: [1] 2 3 4
2007-03-19, 14:22:13
anonymous from United States  
It is great, Thank u
2007-08-24, 08:06:32
anonymous from United Kingdom  
wicked, cheers
2007-11-01, 01:11:03
anonymous from Sweden  
Simple and perfect for me today. thankyou.
2007-11-01, 09:48:23
anonymous from United States  
thank you
2007-11-28, 15:36:55
anonymous from Australia  
Just what I needed. Thanks very much.
2008-01-22, 10:00:54
anonymous from Mairipor„, Brazil  
Very simple and helful! Thanks!

In one row:

2008-03-04, 11:19:00
anonymous from Germany  
Thanks, useful
2008-05-02, 22:12:10
anonymous from India  
Thanks for your great help :)
2008-08-28, 09:41:29
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.
2008-09-24, 00:42:37
Akif from India  
Thnx Yaar
2009-03-05, 10:13:54
anonymous from United States  
even simpler:
2009-05-14, 20:01:21
anonymous from United States  
thanks, big help
2009-06-23, 01:12:06
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 4, other pages: [1] 2 3 4



NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: