How do I select a sibling element using jQuery?

Only Bolivian Here picture Only Bolivian Here · Sep 18, 2011 · Viewed 108.5k times · Source

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'));
    }
});

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", "");

Answer

Madara&#39;s Ghost picture Madara's Ghost · Sep 18, 2011

Use jQuery .siblings() to select the matching sibling.

$(this).siblings('.bidbutton');