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

205
Visualizações
Create a javascript filter on family tree to display or not people

I didn't find such a specific topic so I hope there is anyone here who could help me. Here's the deal: I'm making a family tree, for my personal purpose, and I struggle with finding something viable to filter people on my tree. As a matter of fact, on top of my page, I want to use a filter with and with the different family names appearing in my tree. I want just by clicking on a name, all the people with this name only remain, and so on with the other names.

Here's my shortened HTML:

<div class="searchbar">
            <h3>Title</h3>
            <select>
                <option value="all">TOUS</option>
                <option value="name1">NAME 1</option>
                <option value="name2">NAME 2</option>
                <option value="name3">NAME 3</option>
                <option value="name4">NAME 4</option>
            </select>
        </div>

<div class="content">
            <h2>Gen 0</h2>

            <div class="person origin name1">
                <h3>1 ・ FULL NAME</h3>
                <p>BIRTH</p>
                <p>WEDDING</p>
                <p>DEATH</p>
            </div>

            <h2>Gen -1</h2>

            <div class="person name1">
                <h3>2 ・ FULL NAME</h3>
                <p>BIRTH</p>
                <p>WEDDING</p>
                <p>DEATH</p>
            </div>
            <hr>
            <div class="person name2">
                <h3>3 ・ FULL NAME</h3>
                <p>BIRTH</p>
                <p>WEDDING</p>
                <p>DEATH</p>
            </div>
</div>

and so on. I tried many different kinds of javascript but none of them worked. Could anyone could help me?

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

0

Here you go

$('select.filtter').change(function(){
var filters = $.map($('select.filtter').toArray(), function(e){
    return $(e).val();
}).join(".");
$("div.content").find("div.person").hide();
$("div.content").find("div.person." + filters).show();
if($("div.person:visible").length === 0){
    $(".alert").show()
}else{
    $(".alert").hide()
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<div class="filtters=wrap">
  <label class="visually-hidden" for="data-title">Title</label>
    <select class="filtter" id="data-actor-lang">
        <option value="all">TOUS</option>
        <option value="name1">NAME 1</option>
        <option value="name2">NAME 2</option>
        <option value="name3">NAME 3</option>
        <option value="name4">NAME 4</option>
    </select>
</div>


<div class="content">
  <h2>Gen 0</h2>
  <div class="person origin all name1">
    <h3>1 ・ FULL NAME</h3>
    <p>BIRTH</p>
    <p>WEDDING</p>
    <p>DEATH</p>
  </div>
  <h2>Gen -1</h2>
  <div class="person all name1">
    <h3>2 ・ FULL NAME</h3>
    <p>BIRTH</p>
    <p>WEDDING</p>
    <p>DEATH</p>
  </div>
  <hr>
  <div class="person all name2">
    <h3>3 ・ FULL NAME</h3>
    <p>BIRTH</p>
    <p>WEDDING</p>
    <p>DEATH</p>
  </div>
  <div class="alert" style="display:none;">Sorry, no person found.</div>
</div>

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