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
Post a Comment