How do I select a sibling element using jQuery?

前端 未结 10 1587
渐次进展
渐次进展 2020-12-05 01:29

Can you help me with this jQuery selector?

$(\".auctiondiv .auctiondivleftcontainer .countdown\").each(function () {
    var newValue = parseInt($(this).text         


        
相关标签:
10条回答
  • 2020-12-05 01:55

    Since $(this) refers to .countdown you can use $(this).next() or $(this).next('button') more specifically.

    0 讨论(0)
  • 2020-12-05 01:55

    also if you need to select a sibling with a name rather than the class, you could use the following

    var $sibling = $(this).siblings('input[name=bidbutton]');
    
    0 讨论(0)
  • 2020-12-05 01:56

    Try -

       $(this).siblings(".bidbutton").addClass("disabled").attr("disabled", "");
    
    0 讨论(0)
  • 2020-12-05 01:57

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

    $(this).siblings('.bidbutton');
    
    0 讨论(0)
  • 2020-12-05 02:00

    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.

    $("p").siblings("h4").css({"color": "red", "border": "2px solid red"});

    0 讨论(0)
  • 2020-12-05 02:04

    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.

    0 讨论(0)
提交回复
热议问题