JQuery to select the last cell in a column when using rowspan
I have a table like this:
<table>
<tr><td>Not This</td><td rowspan="3">This</td></tr>
<tr><td>Not This</td></tr>
<tr><td>Not This</td></tr>
<tr><td>Not This</td><td>This</td></tr>
</table>
How can I select only the rightmost cells (containing "This") in each row to set the border color?
I tried something like:
table.find('tr > td:last-child').addClass('someclass');
But this selects the last cells in the 2nd and 3rd rows, even if they are not the rightmost cell.
I do not use border-collapse on my table and prefer to avoid this.
This required a bit of cheating:
$(function() {
$('td:last-child[rowspan]').each(function() {
$(this).parent().nextAll().slice(0,$(this).attr('rowspan')-1).addClass('skip');
});
$('tr:not(.skip) > td:last-child').addClass('someclass');
$('.skip').removeClass('skip');
});
, td, , rowspan. , , "" . , "skip", , , .