Jump to content

How may rows in table?

Recommended Posts

Hi,I am creating a kind of rotation machine but I couldn't figure out how many rows I have in my table? Could someone please help?E.g:I want to know how many rows this table contains, calculated with a java script:

<table id="table"><tr><td>1</td></tr><tr><td>2</td></tr><tr><td>3</td></tr><tr><td>4</td></tr></table>

EDIT: already found the solution, for the people who are interested: document.getElementById('table').rows.length

Link to post
Share on other sites


<script>function countRows(tblId){     var tbl = document.getElementById(tblId);     var tblRows = tbl.getElementsByTagName("tr");      alert(tblRows);}</script>


<table id="table" onload="countRows(this.id)"><tr><td>1</td></tr><tr><td>2</td></tr><tr><td>3</td></tr><tr><td>4</td></tr></table>

This should do the trick

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...