0

Есть несколько блоков такой структуры, но с разным контентом

<div class="filter-section allow-multiple-expanded expanded">
    <header>
        <span class="text">Наличие:</span>

        <button type="button" class="btn-expand"></button>
    </header>
   <div class="expand-content">

      <label class="checkbox-styled">
        <input type="checkbox" value="Y" name="arrFilter_3041_2254365807" id="arrFilter_3041_2254365807" onclick="smartFilter.click(this)"/>
        <span class="checkbox-content">
            <i class="flaticon-check14"></i>
            В наличии
        </span>
      </label>
   </div>
</div>

Скажите пожалуйста как изменить скрипт, чтобы при нажатии на .btn-expand закрывался/открывался .expand-content именно того блока на который было нажато? (в данном случае это происходит со всеми блоками такого класса)

$('.btn-expand').live('click', function(event) {        
     $('.expand-content').toggle('show');
});
2
  • $(this).closest(".filter-section").find(".expand-content").toggle("show");
    – user176262
    4 ноя 2016 в 21:44
  • стоит обновить версию jQuery и заменить live на on
    – Grundy
    4 ноя 2016 в 22:40

1 ответ 1

1

Структура не ясна, от этого, подняться к родительскому элементу header и найти следующий элемент с классом:

$('.btn-expand').live('click', function(event) {        
     $(this).closest('header').next('.expand-content').toggle('show');
});

Ваш ответ

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

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