简体   繁体   中英

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. 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:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM