P
P
partyzanx2017-07-28 10:12:57
JavaScript
partyzanx, 2017-07-28 10:12:57

How to hide one class and show another on button click?

There is a button How to make it so that when you click on it, one class is immediately hidden, and another class is shown, with remembering cookies? And the next time you clicked, the first class was shown again, and the second one also disappeared with remembering the cookie. There is a solution here , but there seems to be without remembering cookies <button id="pinyin-btn"> Сменить плеер</button>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel Kornilov, 2017-07-28
@KorniloFF

Option with adding / removing a class on a button click:

document.getElementById('pinyin-btn').onclick= function(e) {
    // По клику будет появляться / исчезать класс className
    this.classList.toggle('className');
    if(this.classList.contains('className')) {
      // Ставим кукис
    } else {
      // Удаляем кукис
    }
  }

There are enough functions for working with cookies on the Internet.
To use it like this: to prescribe styles for a button without a class and with a class - it will be the same as changing one class to another.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question