[英]Change Font color of tr with jQuery after click on image
I search for a way to change the font color of a tr with jQuery. 我正在寻找一种使用jQuery更改tr字体颜色的方法。 There is an icon in the last cell of every tr. 每个tr的最后一个单元格中都有一个图标。 I want if I click it that the font color of the tr is changed. 我想要单击它以更改tr的字体颜色。 I used this: 我用过这个:
$('#documentsTable tr').live('click', function(){
but it is for clicking on the whole row. 但这是用于单击整行。 What is the best way to manage this? 最好的管理方式是什么?
Best regards 最好的祝福
Assuming the class of your icon is icon
: 假设您的图标类别为icon
:
$('#documentsTable .icon').live('click', function(){
$(this).closest("tr").css("color","yourColor");
});
You can use the :last-child
pseudo-selector to match the last child of each element in the matched set (in this case, the last td
in each tr
within #documentsTable
): 您可以使用:last-child
伪选择器来匹配匹配集中每个元素的最后一个孩子(在这种情况下,是#documentsTable
中每个tr
的最后一个td
):
$('#documentsTable tr td:last-child').live('click', function(){
$(this).closest("tr").css({color: "#ff0000"});
});
To attach the click event handler to an image within that td
, simply add img
to the end of your selector: 要将click事件处理程序附加到该td
的图像,只需将img
添加到选择器的末尾:
#documentsTable tr td:last-child img
Here's a working example . 这是一个有效的例子 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.