Paul Attuck Paul Attuck - 4 months ago 26
CSS Question

:last for table


<tr><td>First Row</td><td>2 Row</td><td>1 last</td></tr>
<tr><td>Middle Row</td><td>2 Row</td><td>2 last</td></tr>
<tr><td>Last Row</td><td>2 Row</td><td>3 last</td></tr>


$('tr').each(function(index) {
$("td:last").css({backgroundColor: 'yellow', fontWeight: 'bolder'});


why this working only for 3 last, but on 1 last and 2 last no? how can i fix it?


You need to add the context of the td, you're already in a for loop so the 'this' variable can be used. In this context 'this' is equal to the tr you're currently iterating on.

$('tr').each(function(index) {
    $("td:last",this).css({backgroundColor: 'yellow', fontWeight: 'bolder'});