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

397
Visualizações
Is there an easy way to show divs by default, then filter/hide on click?

I'm looking for simple and seo/semantic way to filter and sort some content.

Initially all content should be shown, then on click the content should be filtered and only the selected group show.

I'm starting out with the code below as my base. Using widgets as example. Each widget is in its own div containing information about that widget.

Currently the default is to hide all, I'd prefer to show all to be default (I'm not sure why the very first one is showing alone on load.

Is there a way to do it without initially using display:none for the divs, my understanding is this might not be seo friendly.

$('.tab-link').click(function() {
  var contClass = $(this).data('div');
  $('.result-content').hide().filter('.' + contClass).show()
})
.result-content {
  display: none
}

.result-content:first-of-type {
  display: block
}

a {
  display: inline-block;
  margin-right: 10px;
  padding: 5px 0;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<a href="#" class="tab-link" data-div="widgets">All widgets</a>
<a href="#" class="tab-link" data-div="green-widgets">Green</a>
<a href="#" class="tab-link" data-div="red-widgets">Red</a>
<a href="#" class="tab-link" data-div="blue-widgets">Blue</a>

<div class="widgets green-widgets result-content">
  Widget 654
</div>

<div class="widgets green-widgets result-content">
  Widget 989
</div>

<div class="widgets green-widgets result-content">
  Widget 345
</div>

<div class="widgets red-widgets  result-content">
  Widget 563
</div>
<div class="widgets red-widgets  result-content">
  Widget 867
</div>

<div class="widgets blue-widgets result-content">
  Widget 994
</div>
<div class="widgets blue-widgets result-content">
  Widget 924
</div>
<div class="widgets blue-widgets result-content">
  Widget 114
</div>

about 4 years ago · Juan Pablo Isaza
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