javascript - If td has value "No" add class to different td -


i have following code:

<td class="bedrag">     #_att{factuur bedrag} </td> <td class="paid">     #_att{betaald}{ja|nee} </td> 

in td paid option can given yes or no. change background of bedrag depending on chosen in td paid. figured best way go addclass using javascript. googled around while , found piece of code:

jquery('a:contains("sponsored")').closest('.post-item').addclass('sponz');  

i changed fit needs:

$('.paid:contains("nee")').closest('.bedrag').addclass('sponz'); 

but didn't work. tried following code:

$('.paid:contains("nee")').addclass('sponz'); 

this adds class sponz td paid. want add bedrag. tried this:

('.bedrag:has(.paid:contains("nee"))').addclass('sponz'); 

but didn't work.

anyone know how code working add sponz the td bedrag when user selects option nee? in advance!

closest() isn't quite need looks parents. .bedrag sibling of .paid, need use prev() instead:

$('.paid:contains("nee")').prev('.bedrag').addclass('sponz');
.sponz { color: #c00; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <table>    <tr>      <td class="bedrag">bedrag 1</td>      <td class="paid">nee</td>    </tr>    <tr>      <td class="bedrag">bedrag 2</td>      <td class="paid">ja</td>    </tr>    <tr>      <td class="bedrag">bedrag 3</td>      <td class="paid">nee</td>    </tr>  </table>


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -