What jQuery selector would allow me to select the last <td>
in a <tr>
that has more than 1 <td>
? NOTE: I am trying to find an answer which will allow me to use a single selector or a selector followed by a .filter()
rather than using .each()
<table>
<tr>
<td colspan="2">First Cell</td>
<td>Second Cell</td>
</tr>
<tr>
<td colspan="2">Only Cell</td>
</tr>
<tr>
<td>First Cell</td>
<td>Second Cell</td>
<td>Third Cell</td>
</tr>
</table>
At first, I thought td:last-child might work, but it doesn't.
Try this selector:
td:last-child:not(:first-child)
The explanation: In you case the last child is also the first child as it’s the only child of the parent element. If you now select only the last children that are also not the first childen of their parent element, you’ll get only the last children that are not the only children of their parent element.
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