1

Hello I have following HTML Structure:

<div class="form-step2 hidden"></div>
<div class="form-step2 hidden"></div>
<div class="form-step2 hidden"></div>
<div class="form-step2 hidden"></div>
<button type="button" id="addblock" class="btn btn-primary btn-block">+</button>

If i click on the button i want to remove one hidden and than the next hidden. My JS:

$( "#addblock" ).click(function() {
$( ".form-step2" ).next(".form-step2").removeClass("hidden");
});

But this removes all hidden

4 Answers 4

3

Remove the hidden class from the first form-step2 element with class hidden

$("#addblock").click(function() {
  $(".form-step2.hidden:first").removeClass("hidden");
});
.hidden {
  display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="form-step2 hidden">1</div>
<div class="form-step2 hidden">2</div>
<div class="form-step2 hidden">3</div>
<div class="form-step2 hidden">4</div>
<button type="button" id="addblock" class="btn btn-primary btn-block">+</button>

Sign up to request clarification or add additional context in comments.

Comments

3

$("#addblock").click(function() {
  $('.hidden:first').removeClass("hidden");
});
.hidden {
  display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
<div class="form-step2 hidden">A</div>
<div class="form-step2 hidden">B</div>
<div class="form-step2 hidden">C</div>
<div class="form-step2 hidden">D</div>
<button type="button" id="addblock" class="btn btn-primary btn-block">+</button>

Comments

0

Try this :

$( "#addblock" ).click(function() {
    var $step = $( ".form-step2" ).not('.hidden');
    if($step.length<1)
    {
       $( ".form-step2:first" ).removeClass("hidden");
     }
     else
    {
      $step.next(".hidden").removeClass("hidden");
    }

});

Comments

-1

u can try this:

http://codepen.io/pallavi1811/pen/KpBjNL

$( "#addblock" ).click(function() {
  $( ".form-step2" ).siblings(".form-step2").eq(1).removeClass("hidden");
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.