Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide table rows based on child class name using jquery?

I have a lot of rows and I want to hide some tr that doesn't have a specific class.

Example:

<tr id="game-22590" class="game">
    <td class="pos left-edge">
        <div>2</div>
    </td>
    <td class="cost">
        <input class="dollars-paid uncorrected" type="text" value="19,99" tabindex="4">
    </td>
</tr>
<tr id="game-22591" class="game">
    <td class="pos left-edge">
        <div>3</div>
    </td>
    <td class="cost">
        <input class="dollars-paid" type="text" value="23,99" tabindex="4">
    </td>
</tr>

The td.cost has an input with a class or two. I want to hide those rows that doesn't have the uncorrected class.

like image 671
apeiron Avatar asked Jan 20 '26 06:01

apeiron


1 Answers

Use .filter() to selecting rows has uncorrected class.

$("tr.game").filter(function(){
    return $(this).find("input.uncorrected").length == 0;
}).hide();

$("tr.game").filter(function(){
    return $(this).find("input.uncorrected").length == 0;
}).hide();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
  <tr id="game-22590" class="game">
    <td class="pos left-edge">
      <div>2</div>
    </td>
    <td class="cost">
      <input class="dollars-paid uncorrected" type="text" value="19,99" tabindex="4">
    </td>
  </tr>
  <tr id="game-22591" class="game">
    <td class="pos left-edge">
      <div>3</div>
    </td>
    <td class="cost">
      <input class="dollars-paid" type="text" value="23,99" tabindex="4">
    </td>
  </tr>
</table>
like image 171
Mohammad Avatar answered Jan 21 '26 19:01

Mohammad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!