最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Jquery remove class hidden onclick - Stack Overflow

programmeradmin1浏览0评论

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

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

Share Improve this question asked Jul 20, 2015 at 11:38 leks21leks21 111 gold badge1 silver badge2 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 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./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>

$("#addblock").click(function() {
  $('.hidden:first').removeClass("hidden");
});
.hidden {
  display: none;
}
<script src="https://ajax.googleapis./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>

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

});

u can try this:

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

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

评论列表(0)

  1. 暂无评论