[英]How to show the very next div on button click with jQuery?
以下是我的要素。
<div class="first-div">
DIV 1
<button class="next">Next</button>
</div>
<div class="next-div" style="display:none;">
DIV 2
<button class="back">Back</button>
<button class="next">Next</button>
</div>
<div class="next-div" style="display:none;">
DIV 3
<button class="back">Back</button>
<button class="next">Next</button>
</div>
<div class="next-div" style="display:none;">
DIV 4
<button class="back">Back</button>
</div>
如何選擇下一個隱藏的.next-div
元素並顯示它,然后選擇上一個隱藏的元素並使用jQuery顯示它?
您可以使用:
$('.next').click(function(){
$(this).parent().hide().next().show();//hide parent and show next
});
$('.back').click(function(){
$(this).parent().hide().prev().show();//hide parent and show previous
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.