Reputation: 19828
I'm trying to modify every cell in last column in html table. My first try is:
$('#example td:last').each(function(elem) {
//do something with elem
});
But above code modify only last cell in last column (so one cell instead of all cells in column).
How should I change selector to much all td
in last column?
Upvotes: 0
Views: 1383
Reputation: 33880
:last
return a single element, the last element of the jQuery stack. It is exactly the same of doing :
var $td = $('#example td');
$td.eq($td.length - 1);
What you want is the CSS selector :last-child
, which return the last child (huh).
$('#example td:last-child').each(...);
Upvotes: 0
Reputation: 38112
You can do:
$('#example tr').each(function() {
var elem = $(this).find('td:last');
//do something with elem
});
Upvotes: 0