0

Есть много одинаковых контейнеров, все они скрыты изначально, мне надо сделать так, что бы при клике на кнопку появлялся 1 из них, при клике еще 1 раз, появлялся еще 1 и тд., не могу придумать как это сделать.

<button>Добавить контент</button>
<div class="content"><input type ="text"></div>
<div class="content"><input type ="text"></div>
<div class="content"><input type ="text"></div>
<div class="content"><input type ="text"></div>



 .content {
      display: none;
    }

1 ответ 1

2

var count = 0;
$('button').click(function(){
  $('.content').eq(count++).show();
})
.content {
  display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button>Добавить контент</button>
<div class="content"><input type="text"></div>
<div class="content"><input type="text"></div>
<div class="content"><input type="text"></div>
<div class="content"><input type="text"></div>

3
  • 1
    или $('.content').not(':visible').first().show(); и без счетчика) 13 сен 2018 в 12:14
  • Можете оставить свой ответ)
    – user218976
    13 сен 2018 в 12:15
  • Спасибо, прекрасно работает! 13 сен 2018 в 12:21

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.