Reputation: 420
I have an unordered list of checkbox inputs:
<ul>
<li><input type="checkbox">parent
<ul>
<li><input type="checkbox">child
<ul>
<li><input type="checkbox">grandchild
<ul>
<li><input type="checkbox" checked="checked">great grandchild</li>
<li><input type="checkbox">great grandchild</li>
<li><input type="checkbox">great grandchild</li>
<li><input type="checkbox" checked="checked">great grandchild</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
If I uncheck one of the checkboxes, how can I check if any siblings are also checked only from that <ul>
?
I've tried a number of things such as siblings()
, find()
and index()
.
Upvotes: 1
Views: 2053
Reputation: 78690
$(this).parent().siblings().children(":checkbox:checked").length
This should get you the number of "sibling" checkboxes which are checked.
Upvotes: 2