简体   繁体   中英

Hide a row in table with specific number of characters

I need to hide the flight row with the flight number longer than 6 characters (including the EY- ) for example when the page loads the row for the EY-5306 should be hidden completely and only show the row with the flight number EY-513 .

<tr>
   <td>EY-5306</td>
   <td>29 Oct 2019</td>
   <td>07:00 am</td>
   <td>AUH</td>
   <td>AMM</td>
   <td>
      <a href="https://www.example.com?flightNumber=5306" role="link">Check flight status <img src="/images/test0.jpg" alt="image" class="check-flight-arrow"></a>
   </td>
</tr>

<tr>
   <td>EY-513</td>
   <td>29 Oct 2019</td>
   <td>10:35 am</td>
   <td>AUH</td>
   <td>AMM</td>
   <td>
      <a href="https://www.example.com?flightNumber=513" role="link">Check flight status <img src="/images/test1.jpg" alt="image" class="check-flight-arrow"></a>
   </td>
</tr>

When the JS script runs I want to see the table but that exclude the row with the flight number EY-5306 because the number of characters are more than 6.

use .text().length; to get characters count.

 $('tr td:nth-child(1)').each(function(){ var value = $(this).text().length; if (value > 6){ $(this).parent().hide(); } });
 table{ width:100%; border:1px solid #ddd; } td{ border:1px solid #ddd; padding:10px; }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <table> <tbody> <tr><td>EY-5306</td><td>29 Oct 2019</td><td>07:00 am</td><td>AUH</td><td>AMM</td><td><a href="https://www.example.com?flightNumber=5306" role="link">Check flight status <img src="/images/test0.jpg" alt="image" class="check-flight-arrow"></a></td></tr> <tr><td>EY-513</td><td>29 Oct 2019</td><td>10:35 am</td><td>AUH</td><td>AMM</td><td><a href="https://www.example.com?flightNumber=513" role="link">Check flight status <img src="/images/test1.jpg" alt="image" class="check-flight-arrow"></a></td></tr> </tbody> <table>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM