我使用 jquery,我想找到前一个具有“错误”类的 div
我的html代码:
<table class="questions">
<tr>
<td class="heading">1
<div class="error"></div>
</td>
<td colspan="4">
<textarea class="textcontrol required" name='questionT136'>
</textarea>
</td>
</tr>
<tr>
<td></td>
<th><label for="reponse137-3">Très satisfaisant</label></th>
<th><label for="reponse137-4">Satisfaisant</label></th>
<th><label for="reponse137-5">Insatisfaisant</label></th>
</tr>
<tr class="q">
<td class="heading">
2
<div class="error"></div>
</td>
<td class="questionradio"><input class="required" id='reponse137-3'
name='questionN137' type='radio' value='3'></td>
<td class="questionradio"><input class="required" id='reponse137-4'
name='questionN137' type='radio' value='4'></td>
</tr>
</table>
例如,从reponse137-3 开始,我想将值更改为以前的 class="error"。我已经尝试通过以下方式访问该对象:
$('#reponse137-3').prev(".error")
但它不起作用。我认为因为它没有同一个父母,所以我尝试了:
$('#reponse137-3').prev("tr").next(".error")
我能怎么做 ?