Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

252
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!