Need to ensure browser compatibility as well (should work in IE8)
I came across - :nth-last-child(2)
But it is not browser compatible as it is a css3 selector.
Also I came across a tip to get 2nd, 3rd, 4th child as - td:first-child + td + td
But no way of reversing like
td:last-child - td
to get second last child.
I don't want to use jquery.
Is applying class to the second last element is only option ?
The CSS3 nth-last-child is probably the way to go, since support should become more and more common.
Failing this, you could simply add a CSS class to the element in the markup eg:
<tr>
<td>...</td>
<td class = "penultimate">...</td>
<td>...</td>
</tr>
Under the conditions specified, applying class
(or id
) to the second last element is only option.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With