Alex Guerin Alex Guerin - 1 month ago 10
jQuery Question

jQuery: Get last row column selector

I have the following row in a table:

<tr><td>Adric cut-out</td><td><span class="quantity">0</span></td><td>worthless</td></tr>


I've already got the span with the class 'quantity' selected, but I'm having no luck getting the last TD element in the row selected. I can do it by getting its parent, then its parent, then the last TD child element but is there something a little more efficient?

Using this as a start, how would I select the TD element containing the price?
Note, it will always be the last item on the row.

rjz rjz
Answer

If the format is consistent, stepping up and over to the next column should be fairly efficient:

var price = $('.quantity').closest('td').next().html();

It might be faster to simply assign a class (price?) to the last td and collect that, though.

Comments