Accessing table rows length via DOM?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • johkar

    #1

    Accessing table rows length via DOM?

    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.getEle mentById('myTab le').rows.lengt h, 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>


  • Martin Honnen

    #2
    Re: Accessing table rows length via DOM?



    johkar wrote:[color=blue]
    > 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.getEle mentById('myTab le').rows.lengt h, but isn't the rows
    > collection IE specific? I don't understand how I could use childNodes
    > effectively with col and tbody tags. Ideas?[/color]

    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/

    Comment

    Working...