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

256
Visualizações
How to make an instant search for div results?

I have results shows up inside a table, I designed it to show as grid by separating them by td for each.

I used a JS code to filter the results by a text written in textbox, but the only results shows is the labels! I want each td shows as a result, complete with the contents (Image + Input + label).

Here's the JS code & example of a table same what I have:

$(document).ready(function() {
  $("#filter").on("keyup", function() {
    var value = $(this).val().toLowerCase();
    $("#table *").filter(function() {
      $(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
    });
  });
});
<table>
  <input type="text" id="filter">
  <div name="table">
    <td>
      <label>Product1</label>
      <img src='/img/a.jpg'>
      <input type="text" value="55">
    </td>
    <td>
      <label>Product2</label>
      <img src='/img/b.jpg'>
      <input type="text" value="70">
    </td>
    <td>
      <label>Product3</label>
      <img src='/img/c.jpg'>
      <input type="text" value="20">
    </td>
  </div>
</table>

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

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

0

Use closest this link to get parent td from your search and then toggle visibility.

below is logic to your solution.

$(this).closest("td").toggle($(this).text().toLowerCase().indexOf(value) > -1)

$(document).ready(function() {
  $("#filter").on("keyup", function() {
    var value = $(this).val().toLowerCase();


    $("table label").filter(function() {

      $(this).closest("td").toggle($(this).text().toLowerCase().indexOf(value) > -1)

    });
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table>
  <input type="text" id="filter">
  <div name="table">
    <td>
      <label>Product1</label>
      <img src='/img/a.jpg'>
      <input type="text" value="55">
    </td>
    <td>
      <label>Product2</label>
      <img src='/img/b.jpg'>
      <input type="text" value="70">
    </td>
    <td>
      <label>Product3</label>
      <img src='/img/c.jpg'>
      <input type="text" value="20">
    </td>

  </div>
</table>

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