$('#myTable')[0].rows.length //number of rows
$('#myTable')[0].tBodies[0].rows.length //number of rows in the first
tbody
cheers,
- ricardo
On Feb 25, 5:25 am, Alex Wibowo <alexwib...@gmail.com> wrote:
> Hi all,
> I have a code that counts the number of rows in a table...
>
> the table looks like:
>
> <table id="myTable">
> <thead>
> ...
> </thead>
>
> <tbody>
> <tr>
> ....
> </tr>
> </tbody>
> </table>
>
> and my jquery looks like:
>
> $("#myTable tbody:first-child tr").length;
>
> strange enough.... that always returns 0.
> but if i remove the thead from the table... then it will return the correct
> number of rows..
>
> or alternatively, i can keep the thead, but use the following instead:
>
> $("#myTable tbody tr").length;
>
> i.e. without specifying first-child.
>
> Can anyone explain this behaviour?
>
> THanks a lot!
>
> --
> Best regards,
>
> WiB
No comments:
Post a Comment