my code
<table id="mytable">
<tr>
<td>Text 5</td>
<td>Other text 5</td>
<td><input name="name5" value=""></td>
<td><input type="checkbox" value="5" name="records"></td>
</tr>
<tr>
<td>Text 7</td>
<td>Other text 7</td>
<td><input name="name7" value=""></td>
<td><input type="checkbox" value="7" name="records"></td>
</tr>
<tr>
<td>Text 13</td>
<td>Other text 13</td>
<td><input name="name13" value=""></td>
<td><input type="checkbox" value="13" name="records"></td>
</tr>
</table>
get the middle input checkbox with
$('#mytable input[type=checkbox][name=records][value=7]')
good 🙂
now, how can i get the prev input () and the next () input?
i try
$('#mytable input[type=checkbox][name=records][value=2]').prev('input[type=checkbox]')
for prev, but not works 🙁
thanks 🙂
Assuming you have a reference to that middle checkbox in
checkbox, and also assuming that there is only going to be one checkbox descendant of eachtrelement:This gets the ancestor
trelement with.closest(), and then uses.prev()or.next()to select the previous or followingtr, and then finds any checkbox descendants of that.Also note the use of the
:checkboxselector, which is basically a shortcut to the attribute selector you are currently using. You can use either, but the attribute selector is probably a bit faster since it’s a native CSS selector.