Can you help me with this jQuery selector?
你能帮我解决这个jQuery选择器吗?
$(".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'));
}
});
Basically, I want to select the element with .bidbutton class that belongs in the same parent as the .countdown in the each loop:
基本上,我想选择与.bidbutton类相同的元素,该元素与每个循环中的.countdown属于同一个父级:
<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", "");
8 个解决方案
#1
71
Use jQuery .siblings()
to select the matching sibling.
使用jQuery .siblings()来选择匹配的兄弟。
$(this).siblings('.bidbutton');
#2
4
$(this).siblings(".bidbutton")
#3
2
$("h2").siblings().css({"color": "blue"});
Details are described in the source below:
详细信息在以下来源中描述:
http://www.namasteui.com/traversing-siblings/
http://www.namasteui.com/traversing-siblings/
#4
1
Here is a link which is useful to learn about select a siblings element in Jquery.
这是一个链接,有助于了解如何在Jquery中选择一个兄弟元素。
How do I select a sibling element using jQuery
如何使用jQuery选择兄弟元素
$("selector").nextAll();
$("selector").prev();
you can also find an element using Jquery selector
你也可以使用Jquery选择器找到一个元素
$("h2").siblings('table').find('tr');
For more information, refer this link next(), nextAll(), prev(), prevAll(), find() and siblings in JQuery
有关更多信息,请参阅此链接next(),nextAll(),prev(),prevAll(),find()和JQuery中的兄弟
#5
1
jQuery provides a method called "siblings()" which helps us to return all sibling elements of the selected element. For example, if you want to apply CSS to the sibling selectors, you can use this method. Below is an example which illustrates this. You can try this example and play with it to learn how it works.
jQuery提供了一个名为“siblings()”的方法,它可以帮助我们返回所选元素的所有兄弟元素。例如,如果要将CSS应用于同级选择器,则可以使用此方法。下面是一个说明这一点的例子。您可以尝试此示例并使用它来了解它的工作原理。
$("p").siblings("h4").css({"color": "red", "border": "2px solid red"});
$(“p”)。兄弟姐妹(“h4”)。css({“color”:“red”,“border”:“2px solid red”});
#6
0
Since $(this)
refers to .countdown
you can use $(this).next()
or $(this).next('button')
more specifically.
由于$(this)指的是.countdown,你可以更具体地使用$(this).next()或$(this).next('button')。
#7
0
Try -
试试 -
$(this).siblings(".bidbutton").addClass("disabled").attr("disabled", "");
#8
0
If you want to select a specific sibling:
如果要选择特定的兄弟:
var $sibling = $(this).siblings('.bidbutton')[index];
where 'index' is the index of the specific sibling within the parent container.
其中'index'是父容器中特定兄弟的索引。
#1
71
Use jQuery .siblings()
to select the matching sibling.
使用jQuery .siblings()来选择匹配的兄弟。
$(this).siblings('.bidbutton');
#2
4
$(this).siblings(".bidbutton")
#3
2
$("h2").siblings().css({"color": "blue"});
Details are described in the source below:
详细信息在以下来源中描述:
http://www.namasteui.com/traversing-siblings/
http://www.namasteui.com/traversing-siblings/
#4
1
Here is a link which is useful to learn about select a siblings element in Jquery.
这是一个链接,有助于了解如何在Jquery中选择一个兄弟元素。
How do I select a sibling element using jQuery
如何使用jQuery选择兄弟元素
$("selector").nextAll();
$("selector").prev();
you can also find an element using Jquery selector
你也可以使用Jquery选择器找到一个元素
$("h2").siblings('table').find('tr');
For more information, refer this link next(), nextAll(), prev(), prevAll(), find() and siblings in JQuery
有关更多信息,请参阅此链接next(),nextAll(),prev(),prevAll(),find()和JQuery中的兄弟
#5
1
jQuery provides a method called "siblings()" which helps us to return all sibling elements of the selected element. For example, if you want to apply CSS to the sibling selectors, you can use this method. Below is an example which illustrates this. You can try this example and play with it to learn how it works.
jQuery提供了一个名为“siblings()”的方法,它可以帮助我们返回所选元素的所有兄弟元素。例如,如果要将CSS应用于同级选择器,则可以使用此方法。下面是一个说明这一点的例子。您可以尝试此示例并使用它来了解它的工作原理。
$("p").siblings("h4").css({"color": "red", "border": "2px solid red"});
$(“p”)。兄弟姐妹(“h4”)。css({“color”:“red”,“border”:“2px solid red”});
#6
0
Since $(this)
refers to .countdown
you can use $(this).next()
or $(this).next('button')
more specifically.
由于$(this)指的是.countdown,你可以更具体地使用$(this).next()或$(this).next('button')。
#7
0
Try -
试试 -
$(this).siblings(".bidbutton").addClass("disabled").attr("disabled", "");
#8
0
If you want to select a specific sibling:
如果要选择特定的兄弟:
var $sibling = $(this).siblings('.bidbutton')[index];
where 'index' is the index of the specific sibling within the parent container.
其中'index'是父容器中特定兄弟的索引。