Html table row count

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

    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!
  • Martin Honnen

    #2
    Re: Html table row count



    Cris Teta wrote:

    [color=blue]
    > 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?[/color]

    The W3C DOM is publically documented:

    you will find the properties of a HTML <table> element here:

    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.getEle mentById('table Id')
    but of course the DOM has other ways (getElementsByT agName, childNodes,
    first/lastSibling) to access nodes.

    --

    Martin Honnen

    Comment

    • dot

      #3
      Re: Html table row count

      Cris Teta wrote:[color=blue]
      > 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.[/color]

      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.getEle mentById('table Id').rows.lengt h);"></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+.

      Comment

      • ms_chika

        #4
        Re: Html table row count



        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!

        Comment

        • ms_chika

          #5
          Re: Html table row count

          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!

          Comment

          Working...