[英]Jquery: Get row from cell value
I have a table where all my rows are like this: 我有一个表,其中所有行都是这样的:
<tr>
<td class="name">name1</td>
<td class="type">type1</td>
<td class="edit">
<a href="edit" class="edit">edit</a>
</td>
</tr>
I need to disable the edit href for certain types. 我需要禁用某些类型的edit href。 So I need something like:
所以我需要这样的东西:
row = $('.mytable').find(row where .type value = type_with_no_edit) #this is where I need elp
row.find('a.edit').remove();
If the row was alwasy the first one, I would do: 如果该行是第一行,那么我会这样做:
row = $('.mytable tbody>tr:first')
but that's not always the case. 但并非总是如此。
Sounds like a job for filter... 听起来像是过滤工作...
$('.mytable tr').filter(function() {
return $("td.type", this).text() === "type_with_no_edit";
}).find('a.edit').remove();
That finds every row that has the text type_with_no_edit
in the td with the class type and removes the td with a.edit
that is a sibling. 这发现有文本的每一行
type_with_no_edit
与类类型的TD与删除TD a.edit
是兄弟姐妹。
You can use the :contains
pseudo-selector: 您可以使用
:contains
伪选择器:
$('td.type:contains("type_with_no_edit")').siblings('.edit').empty();
Demo: http://jsfiddle.net/XLwfs/ 演示: http : //jsfiddle.net/XLwfs/
If you don't want to empty the TD, just target the anchor and remove it instead. 如果您不想清空TD,只需将锚定为目标并将其移除即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.