假设我有一个 <dl>
所有<dd>
是隐藏的。点击 <dt>
切换 <dd>
使用以下代码跟随它:
$(this).nextUntil('dt').toggle();
http://jsfiddle.net/mblase75/FZQj7/
现在,我想自动隐藏 <dd>
我跟在另一个人后面 <dt>
s,所以我尝试用这段代码捕获 sibling :
$(this).nextUntil('dt').toggle()
.siblings().filter('dd').hide();
http://jsfiddle.net/mblase75/FZQj7/1/
但是没有任何反应,因为每个 <dd>
我已经选择了 .nextUntil
是彼此的 sibling 。结果,它们都被隐藏了,什么也没有显示。
必须有一种紧凑的方式告诉 jQuery 选择所有的 sibling ,除了那些我已经选择但我看不到的 sibling 。想法?
最佳答案
这个怎么样?注意 not
函数的使用,which you can read about here .
http://jsfiddle.net/lbstr/FZQj7/6/
$('dt').on('click',function() {
var $this = $(this),
$firstGroup = $this.nextUntil('dt');
$firstGroup.toggle();
$this.siblings('dd').not($firstGroup).hide();
});
关于javascript - 如何选择多个元素的 siblings()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11582035/