0

This function is fade in and out but only for one row whose id is "AsserRow"

Why it is not working for all rows?

$('#chkTribe').change(function() {
  if (!this.checked) {
    $('#AsserRow').fadeIn('slow');
    $('#FoneRow').fadeIn('slow');
    $('#FtRow').fadeIn('slow');
  } else {
    $('#AsserRow').fadeOut('slow');
    $('#FoneRow').fadeIn('slow');
    $('#FtRow').fadeIn('slow');
  }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<input type="checkbox" id="chkTribe" name="" value=""> <br/>

Rows that need to be hide,
<table>
  <tr id="AsserRow">
    <td>
      <span style="font-weight:bold">Asserah:</span>
    </td>
  </tr>
  <tr id="FoneRow">
    <td>
      <span style="font-weight:bold">FoneRow:</span>
    </td>
  </tr>
  <tr id="FtRow">
    <td>
      <span style="font-weight:bold">FtRow:</span>
    </td>
  </tr>
</table>
mplungjan
  • 169,008
  • 28
  • 173
  • 236
Doc
  • 179
  • 1
  • 18

2 Answers2

1

You had fadeIn too many times in the else

This is simpler

$('#chkTribe').change(function() {
  if (this.checked) {
    $("[id$=Row]").fadeOut('slow'); // Alas no fadeToggle(boolean)
  } else {
    $("[id$=Row]").fadeIn('slow');
  }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<input type="checkbox" id="chkTribe" name="" value=""> <br/>

Rows that need to be hide,
<table>
  <tr id="AsserRow">
    <td>
      <span style="font-weight:bold">Asserah:</span>
    </td>
  </tr>
  <tr id="FoneRow">
    <td>
      <span style="font-weight:bold">FoneRow:</span>
    </td>
  </tr>
  <tr id="FtRow">
    <td>
      <span style="font-weight:bold">FtRow:</span>
    </td>
  </tr>
</table>
mplungjan
  • 169,008
  • 28
  • 173
  • 236
0

You can do this with just CSS ( if the layout is aproximately the same as the one you shared meaning that checkbox and table are siblings and table is after checkbox )

/* add common class to all rows you want to hide
for eg : hide-me */
/* or you could select all the rows that have id's that contain `Row` word
with #chkTribe:checked ~ table tr[id$=Row] */

#chkTribe:checked ~ table .hide-me {
  opacity:0;
  line-height: 0px;
}


table .hide-me {
  transition:0.3s ease-out;
  line-height: 20px;
}
<input type="checkbox" id="chkTribe" name="" value=""> <br/>

Rows that need to be hide,
<table>
  <tr class="hide-me" id="AsserRow">
    <td>
      <span style="font-weight:bold">Asserah:</span>
    </td>
  </tr>
  <tr class="hide-me"  id="FoneRow">
    <td>
      <span style="font-weight:bold">FoneRow:</span>
    </td>
  </tr>
  <tr class="hide-me"  id="FtRow">
    <td>
      <span style="font-weight:bold">FtRow:</span>
    </td>
  </tr>
  <tr>  <td>
      <span style="font-weight:bold">Other row here</span>
    </td>
  </tr>
</table>
Mihai T
  • 17,254
  • 2
  • 23
  • 32