如何使用jQuery选择同级元素? [英] How do I select a sibling element using jQuery?
本文介绍了如何使用jQuery选择同级元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您能帮我这个jQuery选择器吗?
Can you help me with this jQuery selector?
$(".auctiondiv .auctiondivleftcontainer .countdown").each(function () {
var newValue = parseInt($(this).text(), 10) - 1;
$(this).text(newValue);
if (newValue == 0) {
$(this).parent().fadeOut();
chat.verify($(this).parent().parent().attr('id'));
}
});
基本上,我想在每个循环中选择具有.bidbutton类的元素,该元素与.countdown属于同一父级:
Basically, I want to select the element with .bidbutton class that belongs in the same parent as the .countdown in the each loop:
<div class="auctiondivleftcontainer">
<p class="countdown">0</p>
<button class="btn primary bidbutton">Lance</button>
</div>
然后将其应用于该按钮:
And then apply this to that button:
$(button here).addClass("disabled");
$(button here).attr("disabled", "");
推荐答案
使用jQuery .siblings()
选择匹配的兄弟姐妹.
Use jQuery .siblings()
to select the matching sibling.
$(this).siblings('.bidbutton');
这篇关于如何使用jQuery选择同级元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文