Check 'brother' checkbox with jQuery

3

I have two checkbox different in the same column of the table, but both have different names and values.

<td align="center">
   <input type="checkbox" id="chkSiapeServidor" name="chkSiapeServidor"/>
   <input type="checkbox" id="chkIdUnidadeAnterior" name="chkIdUnidadeAnterior"/>
</td>

When I load the page, I check if a hidden is populated and if it is positive, the hidden value in the checkbox. I use this code:

if($('#siapeServidor').prop('value')) {
    $(this).find('td input[type=checkbox][name=chkSiapeServidor][value='+$('#siapeServidor').prop('value')+']').prop('checked', true);
}

How do I mark the checkbox that is at the same level as the referenced, and how to reference the tr parent of the td where they are located?

    
asked by anonymous 29.09.2015 / 00:07

1 answer

2

In your code I think you can remove the condition if because jQuery does not give an error if it does not find the element. And if it is a input you can use .val() which is the API for inputs.

$(this).find('td input[type=checkbox][name=chkSiapeServidor][value='+$('#siapeServidor').val()+']').prop('checked', true);
    
29.09.2015 / 00:12