I have a table where a column in each row consists of the same <select> option like this:
<tr>
....
<td>..</td>
<td>
<select id="gender">
<option value="M">Male</option>
<option value="F">Female</option>
</select>
</td>
</tr>
<tr>
....
<td>..</td>
<td>
<select id="gender">
<option value="M">Male</option>
<option value="F">Female</option>
</select>
</td>
</tr>
<tr>
....
<td>..</td>
<td>
<select id="gender">
<option value="M">Male</option>
<option value="F">Female</option>
</select>
</td>
</tr>
Lets say i’m currently working on the second row, how do I disable the option on the third row?
Use the
closest("selector")method to traverse up to the parent (you could also useparents("selector")), jump to the next one usingnext(), traverse down tofind("selector")and edit the form element withprop().Of course, you’d put this line in some kind of event handler, probably a
changeevent fired by the previousselectelement. However, before you do that, you’ll need to make sure you’re not doubling up onid‘s…otherwise jQuery won’t work so well.