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

186
Vistas
Collapse all head groups when other head group is clicked

I've got the following javascript:

  <script>
    $(document).ready(function()
    {
      if($('div.trigger').length > 0)
      {
        $('div.trigger').click(function()
        {
          if ($(this).hasClass('open'))
          {
            $(this).removeClass('open');
            $(this).addClass('close');
            $(this).next().slideDown(100);
            return false;
          }
          else
          {
            $(this).removeClass('close');
            $(this).addClass('open');
            $(this).next().slideUp(100);
            return false;
          }
        });
      }
    });
  </script>

For example below I've got 2 groups (have many more groups). When I click for instance the group "Producten" I want to close (collapse) the group "Algemeen" and all eventual other groups when they where open. Tried many things but I'm not that much in to javascript, so if you goeroe's have a little advice or solution...

      <div class="trigger open"><a href="#">Algemeen</a></div>
        <div class="cnt">
          <a href="dashboard.php" target="content">Dashboard</a><br>
          <a href="admin_memo.php" target="content">Memo's</a><br>
        </div>
      <div class="clearing">&nbsp;</div>
      <div class="trigger open"><a href="#">Producten</a></div>
        <div class="cnt">
          <a href="product_home.php" target="content">Product zoeken</a><br>
          <a href="product_new.php" target="content">Product aanmaken</a><br>
          <a href="product_sort.php" target="content">Producten volgorde</a><br>
          <a href="unit_new.php" target="content">Product eenheden</a><br>
          <a href="option_new.php" target="content">Productopties</a><br>
          <a href="option_sort.php" target="content">Productopties volgorde</a><br>
        </div>
      <div class="clearing">&nbsp;</div>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Here's a much simpler way, using css transition and a little jquery.

$(document).ready(function() {
  $('div.trigger').click(function() {
    $(this).next().toggleClass('open');
    $('div.trigger').not($(this)).next().removeClass('open');
  });
});
.box {
  transition: height .5s;
  height: 0px;
  background: #333;
}

.trigger {
  margin-top: 15px;
  padding: 10px;
  cursor: pointer;
}

.box.open {
  height: 100px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class='trigger'>trigger</div>
<div class='box'></div>
<div class='trigger'>trigger</div>
<div class='box'></div>
<div class='trigger'>trigger</div>
<div class='box'></div>

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