0<...">

JQuery: select last row column selector

I have the following line in my table:

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

      

I already got a range with the selected "count", but I am unable to get the last TD element in the selected row. I can do this by getting its parent, then its parent, then the last TD child, but is there something more efficient?

Using this as a start, how would you select the TD element that contains the price? Note that this will always be the last item on the line.

+3


source to share


3 answers


If the format is consistent, moving to the next column should be efficient enough:

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

      



It might be easier to just assign the class ( price

?) To the latter td

and build it, however.

+3


source


Take a look here: http://jsbin.com/odacar

What the last TD warns by using this:



function doAlert() {
  alert($('td:last').html());
}

      

+2


source


You can use the last selector - http://api.jquery.com/last-selector/

$ ('tr') children ('td: last').

0


source







All Articles