dan_vitch
dan_vitch

Reputation: 4559

Getting more than expected with siblings().length

I have the following html

<div id="myDiv">
<table>
    <tbody>
        <tr></tr>
        <tr></tr>
        <tr></tr>
        <tr></tr>
        <tr></tr>
        <tr></tr>
        <tr></tr>
        <tr></tr>
    </tbody>
</table>
</div>

When I execute this jquery code

var count = $('#myDiv table tbody tr').siblings().length;

I am expecting to get 8 as the value of count, instead I am getting 45. There is more html on the page than the area I have shown, and each of the above elements hold various amounts of data. What am I missing?

Upvotes: 2

Views: 2793

Answers (1)

Arsen K.
Arsen K.

Reputation: 5660

var count = $('#myDiv table tbody tr').length;

or

var count = $('#myDiv tr').length;

Upvotes: 2

Related Questions