By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,034 Members | 1,777 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,034 IT Pros & Developers. It's quick & easy.

Html table row count

P: n/a
Hi to all,

im just newbie in javascript and html dom. I just want to know how will
i get the total number of rows in a certain html table? Please help, it
will be very much appreciated. Thanks in advance.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a


Cris Teta wrote:

im just newbie in javascript and html dom. I just want to know how will
i get the total number of rows in a certain html table?


The W3C DOM is publically documented:
http://www.w3.org/TR/DOM-Level-2-HTML/
you will find the properties of a HTML <table> element here:
http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-64060425
So the rows property is what you are looking for which then has a
property length you can check.
As for accessing a certain HTML table that is not different from a
accessing any other certain element, if the table has an id attribute
you can use
var table = document.getElementById('tableId')
but of course the DOM has other ways (getElementsByTagName, childNodes,
first/lastSibling) to access nodes.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2

P: n/a
dot
Cris Teta wrote:
Hi to all,

im just newbie in javascript and html dom. I just want to know how will
i get the total number of rows in a certain html table? Please help, it
will be very much appreciated. Thanks in advance.


The table-element has a rows collection which you could find the length
of (the rows collection works as an array).

Example:
<table id="tableId">
<tr><td>Row 1</td></tr>
<tr><td>Row 2</td></tr>
<tr><td>Row 3</td></tr>
</table>
<form><input type="button" value="Count Table Rows"
onclick="alert(document.getElementById('tableId'). rows.length);"></form>

Note that it only counts the rows in the specified table - not also the
rows of the tables inside the table.

Works in IE5+ and NN6+.
Jul 23 '05 #3

P: n/a


Hi, thanks to ur reply! It's really a quick reply. thanks, thanks a lot
;)

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #4

P: n/a
It's really a quick reply.
thanks a lot!

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.