我有一张表,我的所有行都是这样的:
<tr>
<td class="name">name1</td>
<td class="type">type1</td>
<td class="edit">
<a href="edit" class="edit">edit</a>
</td>
</tr>
我需要禁用某些类型的编辑href。 所以我需要这样的东西:
row = $('.mytable').find(row where .type value = type_with_no_edit) #this is where I need elp
row.find('a.edit').remove();
如果第一行是alwasy,我会这样做:
row = $('.mytable tbody>tr:first')
但情况并非总是如此。
答案 0 :(得分:4)
听起来像是过滤器的工作......
$('.mytable tr').filter(function() {
return $("td.type", this).text() === "type_with_no_edit";
}).find('a.edit').remove();
找到td中具有类型类型的文本type_with_no_edit
的每一行,并删除带有a.edit
兄弟的td。
答案 1 :(得分:2)
您可以使用:contains
伪选择器:
$('td.type:contains("type_with_no_edit")').siblings('.edit').empty();
如果您不想清空TD,只需定位锚点并将其删除即可。