最善の方法はIndex
、要素div
を非表示のトリガーとして使用することです。
次に、JavaScriptで宣言しますvar count = 0
次のクリックごとに がインクリメントされますcount
。
$('#next-button').on("click" function(){
count++; // increment (decrement if its prev-button)
$('.DIV_class').fadeOut(0); // hide all class
$('.DIV_class').eq(count).fadeIn(0); // will show only the index of that class.
});
より保守しやすく、読みやすくなっています。
このコードはまだテストしていませんが、参考にしていただければ幸いです。