471,119 Members | 1,376 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,119 software developers and data experts.

Html table row count

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
4 65666


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
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


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
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.

Similar topics

1 post views Thread by Hitit | last post: by
3 posts views Thread by Al Wilkerson | last post: by
1 post views Thread by Al Wilkerson | last post: by
5 posts views Thread by aljamala | last post: by
8 posts views Thread by roop1 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.