[英]jQuery check siblings with certain class
I'm working on a site that has a weird html formatting. 我正在使用具有怪异html格式的网站。 See html below.
请参阅下面的html。 Basically when a checkbox
.group
is clicked on, All the .item
checkboxes that follows should get checked until it hits the next .groupparent
div. 基本上一个复选框时
.group
被点击,所有.item
遵循复选框都应该得到遏制,直至碰到下一个.groupparent
股利。 How would approach this. 如何处理这个问题。 Note: there's also a number inside
<b>
tags that we can also use to count the next .items
that need to be checked. 注意:
<b>
标记中还有一个数字,我们也可以使用它来计数下一个需要检查的.items
。 I appreciate your input. 感谢您的投入。 I'm using jQuery.
我正在使用jQuery。
<div class="groupparent"><input type="checkbox" class="group" /><b>3</b></div>
<input type="checkbox" class="item" />
<input type="checkbox" class="item" />
<input type="checkbox" class="item" />
<div class="groupparent"><input type="checkbox" class="group" /><b>2</b></div>
<input type="checkbox" class="item" />
<input type="checkbox" class="item" />
<div class="groupparent"><input type="checkbox" class="group" /><b>4</b></div>
<input type="checkbox" class="item" />
<input type="checkbox" class="item" />
<input type="checkbox" class="item" />
<input type="checkbox" class="item" />
<div class="groupparent"><input type="checkbox" class="group" /><b>6</b></div>
<input type="checkbox" class="item" />
<input type="checkbox" class="item" />
<input type="checkbox" class="item" />
<input type="checkbox" class="item" />
<input type="checkbox" class="item" />
<input type="checkbox" class="item" />
I'm assuming the class name as groupparent
then I think this will do 我假设班级名称为
groupparent
那么我认为这会做
$(this).parent().nextUntil('.groupparent').filter('.item')
You can use jQuery.nextUntil selector here. 您可以在此处使用jQuery.nextUntil选择器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.