How do I close the content of a button?

  • 0
    Hello.
    I need to hide the contents of the previous ones when I click on the next button.
    And tell me, am I doing the right thing?
    There will be about ten buttons, when you click on the button, several blocks should open (for example, in my case, text and a city map. Pressing, for example, Astrakhan, opens the text in one block and the city map across the entire width of the screen below).
    JavaScript Juliet Logan, Nov 18, 2020

  • 1 Answers
  • 0
    <div class="container">
    <a href="#" class="show">Первая ссылка</a>
    <div hidden class="content">
    <div>А</div>
    <div>Б</div>
    <div>В</div>
    </div>
    </div>
    <div class="container">
    <a href="#" class="show">Вторая ссылка</a>
    <div hidden class="content">
    <div>Г</div>
    <div>Д</div>
    <div>Е</div>
    </div>
    </div>
    <div class="container">
    <a href="#" class="show">Третья ссылка</a>
    <div hidden class="content">
    <div>Е</div>
    <div>Ж</div>
    <div>Е</div>
    </div>
    </div>


    $('.show').on('click', function(){
    $('.container > .content').attr('hidden','');
    $(this).next('.content').prop('hidden', false);
    });
    Anonymous

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