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

152
Visualizações
How to collapse a specific section of footer menu after click on mobile

I'm trying to create a responsive footer for mobile so that when users click on one of the titles the elements of that section expand while the other elements of the other remain collapsed and when clicked again it collapses. So far I only manage to create a functionality where after clicking one all element of all expands.

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<div>
  <div class="nav-footer">
    <div class="nav">
      <h2 class="title">Legal</h2>
      <ul class="list">
        <li>Privacy Policy</li>
        <li>Terms & Conditions</li>
      </ul>
    </div>
    <div class="nav">
      <h2 class="title">Company</h2>
      <ul class="list">
        <li>About us</li>
        <li>Mission</li>
      </ul>
    </div>
    <div class="nav">
      <h2 class="title">Assistance</h2>
      <ul class="list">
        <li>FAQ</li>
        <li>Contact</li>
      </ul>
    </div>
  </div>
</div>

CSS

.list {
  max-height: 0; 
  overflow:hidden; 
  transition: max-height 1s ease-out;
}

.title {
  cursor: pointer;
}

.test {
  height:auto; 
  max-height: 500px; 
  transition: max-height 0.5s ease-in !important;
}

JS

jQuery(" h2").click(function(){
    $("ul").toggleClass("test");
});

Thank you in advance for your time!

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You can use $(this).next("ul").toggleClass("test"); to find the ul "related" to your h2.

Demo

jQuery(" h2").click(function(){
    $(this).next("ul").toggleClass("test");
});
.list {
  max-height: 0; 
  overflow:hidden; 
  transition: max-height 1s ease-out;
}

.title {
  cursor: pointer;
}

.test {
  height:auto; 
  max-height: 500px; 
  transition: max-height 0.5s ease-in !important;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div>
  <div class="nav-footer">
    <div class="nav">
      <h2 class="title">Legal</h2>
      <ul class="list">
        <li>Privacy Policy</li>
        <li>Terms & Conditions</li>
      </ul>
    </div>
    <div class="nav">
      <h2 class="title">Company</h2>
      <ul class="list">
        <li>About us</li>
        <li>Mission</li>
      </ul>
    </div>
    <div class="nav">
      <h2 class="title">Assistance</h2>
      <ul class="list">
        <li>FAQ</li>
        <li>Contact</li>
      </ul>
    </div>
  </div>
</div>

about 4 years ago · Santiago Trujillo 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