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", "");
jQuery siblings() Method The siblings() method returns all sibling elements of the selected element. Sibling elements are elements that share the same parent. The DOM tree: This method traverse forward and backwards along siblings of DOM elements.
Answer: Use the Attribute Selector You can use the CSS attribute selectors to select an HTML element by name using jQuery. The attribute selectors provide a very flexible and powerful mechanism for selecting elements.
jQuery prev() Method The prev() method returns the previous sibling element of the selected element. Sibling elements are elements that share the same parent.
Use jQuery .siblings()
to select the matching sibling.
$(this).siblings('.bidbutton');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With