Jump to content

How may rows in table?


Yami King

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 comment
Share on other sites

JavaScript

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

HTML

<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 comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...