0

Есть переключатель:

$(".main-nav-chat .options").click(function() {
  $(".wrapperchat").toggleClass("wrapperchat-bottom");
});

Как к нему привязать Local Storage, чтобы запоминался класс wrapperchat-bottom?

Можно его переделать, только чтобы смысл не поменялся.

1
  • Да.............
    – steep
    14 дек 2019 в 18:23

1 ответ 1

1
<div class="wrapperchat">
   <div class="main-nav-chat">
      <div class="options">кнопка</div> 
   </div>
</div>

var active = localStorage['active'] == 'true';
$(".wrapperchat").toggleClass("wrapperchat-bottom", active);
$(".main-nav-chat .options").click(function(e) {
    e.preventDefault();
    active = !active;
    localStorage['active'] = active;
$(".wrapperchat").toggleClass("wrapperchat-bottom");
});
1
  • 1
    e.preventDefault(); не нужен, у дива нет действия по умолчанию.
    – Kirill
    17 дек 2019 в 20:59

Ваш ответ

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

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