开发者

Change Font color of tr with jQuery after click on image

开发者 https://www.devze.com 2023-04-05 02:15 出处:网络
I search for a way to change the font color of a tr with jQuery. There is an icon in the last cell of every tr. I want if I click it that the font color of the tr is changed. I used this:

I search for a way to change the font color of a tr with jQuery. There is an icon in the last cell of every tr. I want if I click it that the font color of the tr is changed. I used this:

$('#documents开发者_如何学GoTable 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:

$('#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):

$('#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:

#documentsTable tr td:last-child img

Here's a working example.

0

精彩评论

暂无评论...
验证码 换一张
取 消