Yami King Posted December 4, 2005 Share Posted December 4, 2005 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 More sharing options...
aspnetguy Posted December 5, 2005 Share Posted December 5, 2005 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now