[英]jQuery addClass only to <td> where the parent <tr> has specific class
so what i try to do is, to add a class to every element, where the parent has a specific class. 所以我尝试做的是,为每个元素添加一个类,其中父类具有特定的类。
I tried this: 我试过这个:
if ($('tr').hasClass('storno')) {
$('tr > td').addClass('storno');
}
and this is the html example: 这是html示例:
<table>
<tr class="storno">
<td>test</td>
<td>test2</td>
</tr>
<tr>
<td>test</td>
<td>test2</td>
</tr>
</table>
i tried it also with some other code, but at this point, i dont know i can get it right. 我也尝试了其他一些代码,但在这一点上,我不知道我能做对。
Thank you very much in advance 非常感谢你提前
$('tr.storno > td').addClass('storno');
you need to use the class selector along with descendent selector to do this 您需要使用类选择器和后代选择器来执行此操作
$('tr.storno td').addClass('storno');
做这个
$('tr.storno > td').addClass('storno');
在获取节点时,只需使用具有特定类的选择器:
$('tr.specificParentClass').children('td').addClass('tdClass');
在这里试试这个
$('tr.storno').find('td').addClass('storno');
if ($('tr').hasClass('storno')) {
$(this).find('td').addClass('storno');
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.