admin管理员组文章数量:1313730
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 badges4 Answers
Reset to default 3Remove 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");
});
本文标签: javascriptJquery remove class hidden onclickStack Overflow
版权声明:本文标题:javascript - Jquery remove class hidden onclick - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741958201a2407111.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论