I would like to create a click event on all input buttons that have the class "add-another". When the buttons are clicked, I want them to reveal next TWO divs with the class "hiddenDV". My event only works for the first element. I have also tried using the on() method and had no luck with this either.
$(".hiddenDV").hide();
$(".add-another").click(function() {
$(this).nextAll('.hiddenDV:lt(2)').show();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div class="panel-body">
<div class="row">
<div class="col-md-12">
<input type="text" placeholder="name"/>
</div>
</div>
<input type="button" class="btn btn-default extra-margin add-another" value="+" />
<div class="row hiddenDV">
<div class="col-md-12">
<input type="text" placeholder="name"/>
</div>
</div>
<div class="row hiddenDV">
<div class="col-md-12">
<input type="text" placeholder="name"/>
</div>
<input type="button" class="btn btn-default extra-margin add-another" value="+" />
<input type="button" class="btn btn-default" value="-" />
</div>
<div class="row hiddenDV">
<div class="col-md-12">
<input type="text" placeholder="name"/>
</div>
</div>
<div class="row hiddenDV">
<div class="col-md-12">
<input type="text" placeholder="name"/>
</div>
<input type="button" class="btn btn-default extra-margin add-another" value="+" />
<input type="button" class="btn btn-default" value="-" />
</div>
</div>
.hiddenDVelements in CSS, then your code it working absolutely fine: jsfiddle.net/88645xca+is inside the div meaning it is not sibling anymore this code works if the button and the hidden div are siblings