jquery - Check if element exist in row, but limit only to current row -


i have table looks this:

<table>  <tr><td><input class="serv1" type="checkbox" name="ser1[]" id="ser1[]" value="yes"></td><td><input class="serv2" type="checkbox" name="ser2[]" id="ser2[]" value="yes" ></td><td><input class="serv3" type="checkbox" name="ser3[]" id="ser3[]" value="yes" ></td></tr>  <tr><td><input class="serv1" type="checkbox" name="ser1[]" id="ser1[]" value="yes"></td><td></td><td><input class="serv3" type="checkbox" name="ser3[]" id="ser3[]" value="yes"></td></tr> </table> 

with jquery, when clicking on i.e ser3[] (first row) check if ser2[] (also in first row) checked, if not not allow if checked.

in row 2 not have ser2[] have check if ser2[] exist if not, check if ser1[] checked (there ser1[] , ser3[])

my code follow: (i inserted part of code i'm having trouble with)

$('.serv3').change(function() { if($(this).parents('tr').find('td.serv2')){         alert('exist')}     else{         alert('not exist')     }  }); 

my problem in row 2 when check ser3[] finds ser2[], , can presume finding ser2[] in row 1. question how can limit .find() current row only.

thanks!

you can right

$('.serv3').on('change', function () {    if($(this).closest('td').siblings('td').find('.serv2').length){       alert('exist');    }    else{       alert('not exist');    } 

});


Comments