html - Modifying table rows with jQuery -




i have small table want modify jquery. don't have ability change classes on static html needs done via jquery. i'd see if td class=x says '48 hour hold' td class=y in , in tr changed unavilable. don't know how exclude things in different tr.

<table>   <tr>     <td class="x">48 hour hold</td>     <td class="y">available</td>   </tr>   <tr>     <td class="x">reference desk</td>     <td class="y">available</td>   </tr> </table> 
$(document).ready(function(){   if($(".x:contains(48 hour hold)")){     $(".y:contains(available)").text('unavailable');   }; }) 

the result should this:

<table>   <tr>     <td class="x">48 hour hold</td>     <td class="y">unavailable</td>   </tr>   <tr>     <td class="x">reference desk</td>     <td class="y">available</td>   </tr> </table> 

you don't need if condition, can select .x elements contain given string amend text() of next('.y') element, this:

$('.x:contains("48 hour hold")').next('.y').text('unavailable');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <table>    <tr>      <td class="x">48 hour hold</td>      <td class="y">available</td>    </tr>    <tr>      <td class="x">reference desk</td>      <td class="y">available</td>    </tr>    <tr>      <td class="x">48 hour hold</td>      <td class="y">available</td>    </tr>  </table>





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -