I’m new with jquery and I want to count the existing elements from a table and the html structure is like:
<table summary="">
<tr>
<td>
<table id="myid" some more attributes> <-- i got that id and
<tbody>
<tr>foo</tr> <---counting
<tr>bar</tr> <---counting
</tbody>
</table>
</td>
</tr>
</table>
HTML is apex gernerated.
i’ve tried jquery statements from jQuery: count number of rows in a table an many more sits but nothing worked for me.
My not working “solution” is
$("table[id='myid'] > tbody >tr").length
or
$('table#myid >tbody:last >tr').length
I’m thankful for any hints and tips
Mario
What you have is what you should use, just with the right id:
or
Demo: http://jsfiddle.net/Guffa/bbV3Z/
As the id should be unique in the page, you should be able to use just:
The reason for using
#myid > tbody > trinstead of just#myid tris to make sure that you only get the rows in that specific table, and not rows from tables nested inside it. If you don’t have any tables nested inside it, you can just use: