How do I keep the style when updating a block?

  • 0
    Please tell me what is missing in this script?

    The cookie saves. Closed the block, it will be closed. Opened the block, it will be open.

    Also, the class replacement I need for the open and close block button works.

    But I just can't get it to work, saving the replaced class for the open and close button when the page is refreshed. To make it like this: If you clicked close, then the applied class remains after the page is refreshed, and in the same way, if you clicked open the block, then the applied class also remained after the refresh.

    $(document).ready(function() {
      $("a.knopka").click(function() {
       if ($("div#block").is(':hidden')) { 
       $( "a" ).removeClass( "knopka" ).addClass( "yourClass" );  // замена при нажатии
         $.cookie('TEST', 'false', { expires: 7 }); 
       } else {
       $( "a" ).removeClass( "yourClass" ).addClass( "knopka" ); // вовзрат при нажатии
         $.cookie('TEST', 'true', { expires: 7 });
      if ( $.cookie('TEST') != null) {
        if (  $.cookie('TEST') == 'false') {

    <a class="knopka" >открыть закрыть</a>
    <div id="block">
    Инфа скрыть показать
    JavaScript Anonymous, Aug 31, 2020

  • 1 Answers
  • 0

    Somehow so probably

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!