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

Accessing table rows length via DOM?

P: n/a
I have a table, simplified below, which has <col> and <tbody> elements. Is
there an easy way using DOM to access the table row length? The number of
rows varies as it is generated by an application.

I know you can use rows collection like
document.getElementById('myTable').rows.length, but isn't the rows
collection IE specific? I don't understand how I could use childNodes
effectively with col and tbody tags. Ideas?

John

<table width="50%" border="1" cellspacing="0" cellpadding="0" id="myTable">
<col /><col /><col /><col /><col /><col /><col /><col /><col /><col /><col
/><col />
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tbody>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</tbody>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
Jul 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a


johkar wrote:
I have a table, simplified below, which has <col> and <tbody> elements. Is
there an easy way using DOM to access the table row length? The number of
rows varies as it is generated by an application.

I know you can use rows collection like
document.getElementById('myTable').rows.length, but isn't the rows
collection IE specific? I don't understand how I could use childNodes
effectively with col and tbody tags. Ideas?


The rows collection is part of the W3C DOM Level 2 HTML, both for
<table> elements and for <tbody> elements
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.