Mark checkbox 'brother' with jQuery

Asked

Viewed 65 times

3

I have two checkbox different in the same table column, 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 loading the page, I check if a hidden is completed and if so hidden at 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 father of td where they are located?

1 answer

2


In your code I believe you can withdraw the condition if jQuery does not fail if it does not find the element. And if it is a input you can use the .val() which is the API for inputs.

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.