【发布时间】:2023-03-30 05:50:02
【问题描述】:
具有以下html结构:
<tr class="invisible">
<td align="center">
<a class="i_edit" data-target="30"></a>
</td>
<td class="category">
<span class="f_type" style="background-image: url(/admin/assets/img/f_type_3.gif);"> Tests </span>
</td>
<td style="background-color: blue;">
<select class="behaviour" name="behaviour" style="opacity: 1;">
<option selected="" value="1" style="opacity: 1;">Por noticias destacadas</option>
<option value="2" style="opacity: 1;">Por fecha</option>
</select>
</td>
</tr>
在里面访问 .i_edit 类的最佳/最快方法是:
$('.behaviour').change(function(){
$(this).closest('.i_edit').css('background-color', 'red'); //doesn't work
$(this).parent().closest('.i_edit').css('background-color', 'red'); //doesn't work
$(this).parent().parent().find('.i_edit').css('background-color', 'red'); //this works
return false;
});
【问题讨论】:
-
好吧,如果前两个不起作用,我会说第三个是最好的。
标签: javascript jquery parent closest