Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

109
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda