$(".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 lớn select the element with .bidbutton class that belongs in the same parent as the .countdown in the each loop:
And then apply this khổng lồ that button:
$(button here).addClass("disabled");$(button here).attr("disabled", "");


Highest score (default) Trending (recent votes count more) Date modified (newest first) Date created (oldest first)



you can use $(this).siblings(".bidbutton").addClass("disabled");$(this).siblings(".bidbutton").attr("disabled","");
$("selector").nextAll(); $("selector").prev(); you can also find an element using Jquery selector
$("h2").siblings("table").find("tr");
If you want to select a specific sibling:
var $sibling = $(this).siblings(".bidbutton") Bạn đang xem: How to select sibling elements in jquery
Since $(this) refers to .countdown you can use $(this).next() or $(this).next("button") more specifically.
also if you need khổng lồ select a sibling with a name rather than the class, you could use the following
var $sibling = $(this).siblings("input
If I understood that correctly you"re already in a loop (each) so you would always want to lớn select that one sibling button inside each loop runthrough?Since siblings() returns an array, this would be the way lớn go:
$(this).siblings(".bidbutton")<0>You can apply both things you wanted in a single line doing this:
$(this).siblings(".bidbutton")<0>.addClass("disabled").attr("disabled", "");
Thanks for contributing an answer to lớn Stack Overflow!
But avoid …
Asking for help, clarification, or responding lớn other answers.Making statements based on opinion; back them up with references or personal experience.To learn more, see our tips on writing great answers.
Post Your Answer Discard
By clicking “Post Your Answer”, you agree khổng lồ our terms of service, privacy policy và cookie policy
Site design / hình ảnh © 2022 Stack Exchange Inc; user contributions licensed under CC BY-SA. Rev2022.12.5.43077
Your privacy
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.