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

162
Views
How to show/hide tr if there td's have same value

how to do show/hide only those tr if there last 2 td have same text.in this table i want to 3rd tr and 4th tr show hide. its have same value.

<table  class="table table-zeroBorder sticky-table vrt_table" id="tabledata">
   <thead >
      <th >&nbsp;</th>
   
      <th "> Alto STD </th>
      <th > Alto LXI </th>
   </thead>
   <tbody >
     
      <tr >
         <td >Wheel Covers</td>
         
         <td>
             Center Cap
         </td>
         <td >
            Full
         </td>
      </tr>
      <tr >
         <td >Body Coloured Bumpers</td>
         
         <td >
          - 
         </td>
         <td >
            yes
         </td>
      </tr>
      <tr >
         <td>Body Coloured Outside Door Handles </td>
        
         <td >
             yes 
         </td>
         <td >
            yes
         </td>
      </tr>
      <tr>
         <td >Body Side Molding</td>
        
         <td >
             - 
         </td>
         <td >
             - 
         </td>
      </tr>
      <tr >
         <td >High-Mounted Stop Lamp</td>
         
         <td >
             yes
         </td>
         <td >
          
         </td>
      </tr>
   </tbody>
</table>

My jquery code here.this jquery code hide all tr which have '-' value . in this table i want to 3rd tr and 4th tr show hide. its have same value.

$("#tabledata tbody tr td:contains('" + '-' + "')").filter(function () {
      return $(this).text().trim() == '-';
    }).parent().toggle();
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You'd need to iterate all the <tr> elements, check the <td> contents and toggle visibility accordingly

$("#hide-rows").on("click", () => { 
  $("#tabledata tbody tr").each((_, tr) => {
    // Wrap the <tr> in a jQuery object
    const $tr = $(tr)

    // get the last two <td> children
    const cells = $tr.find("td").slice(-2)

    // get all the unique values
    const values = new Set(cells.map((_, { textContent }) =>
      textContent.trim()).get())

    // Toggle the <tr>
    $tr.toggle(values.size === 1)
    
    // or without using a Set
    // $tr.toggle(cells.eq(0).text().trim() === cells.eq(1).text().trim())    
  })
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table border="1" id="tabledata"> <thead > <th >&nbsp;</th> <th> Alto STD </th> <th > Alto LXI </th> </thead> <tbody > <tr > <td >Wheel Covers</td><td> Center Cap </td><td > Full </td></tr><tr > <td >Body Coloured Bumpers</td><td > - </td><td > yes </td></tr><tr > <td>Body Coloured Outside Door Handles </td><td > yes </td><td > yes </td></tr><tr> <td >Body Side Molding</td><td > - </td><td > - </td></tr><tr > <td >High-Mounted Stop Lamp</td><td > yes </td><td > </td></tr></tbody></table>

<p><button id="hide-rows" type="button">Hide rows</button></p>

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!