Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

107
Visualizações
Toggle between different divs

I need a solution for toggle between divs. I have a sidebar with a group of buttons. When I enter the page with the sidebar I only want the div with the button group to appear, but when I press for example Info I want the info div to appear and the other divs to disappear, and when I press the back button on the Info div I again only want the button group to appear.

.info {
  border-color: black;
  background-color: #f1f1f1;
  margin-left: 7%;
  margin-right: 7%;
  height: 60%;
  position: relative;
}
.about {
  display: none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
 <body>
    <div class="sidebar">
      <h3>Metadata & additional services</h3>
      <div class="button-group" id="showall">
        <button class="activeButton" id="info-button">Info</button>
        <button class="activeButton">Quotes</button>
        <button class="activeButton">Additional</button>
        <button class="activeButton">Additional</button>
      </div>
      <div class="info" id="info">
        <h3>Info</h3>
        <ul>
          <li>Author:</li>
          <li>Title:</li>
          <li>Content:</li>
        </ul>
        <button class="back-button">Back</button>
      </div>
      <div class="about" id="about">
        <h1>about</h1>
      </div>
    </div>

    <script>
      $(document).ready(function () {
        $("#info-button").click(function () {
          $("showall").hide();
          $("#info").show();
        });
      });
    </script>
  </body>

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You are missing the id identifier in your .click function. If you want the info div hidden on page load, make sure to set it to display none, then add another event handler for the #backBtn

$(document).ready(function () {
        $("#info-button").click(function () {
          $("#showall").hide();
          $("#info").show();
        });
        $("#backBtn").click(function () {
          $("#showall").show();
          $("#info").hide();
        });
      });
.info {
  display: none;
  border-color: black;
  background-color: #f1f1f1;
  margin-left: 7%;
  margin-right: 7%;
  height: 60%;
  position: relative;
}
.about {
  display: none;
}
<!DOCTYPE html>
<html>
<head>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js" referrerpolicy="no-referrer"></script>
</head>
   <body>
    <div class="sidebar">
      <h3>Metadata &amp; additional services</h3>
      <div class="button-group" id="showall">
        <button class="activeButton" id="info-button">Info</button>
        <button class="activeButton">Quotes</button>
        <button class="activeButton">Additional</button>
        <button class="activeButton">Additional</button>
      </div>
      <div class="info" id="info">
        <h3>Info</h3>
        <ul>
          <li>Author:</li>
          <li>Title:</li>
          <li>Content:</li>
        </ul>
        <button class="back-button" id="backBtn">Back</button>
      </div>
      <div class="about" id="about">
        <h1>about</h1>
      </div>
    </div>

    <script>
      $(document).ready(function () {
        $("#info-button").click(function () {
          $("showall").hide();
          $("#info").show();
        });
      });
    </script>
  </body>

</html>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda