I am having problem using variables as selectors with jquery.
how do I select last td using $t?
<table id="mytable">
<tr>
<td>a</td>
<td>b</td>
</tr>
</table>
var $t = $('#mytable')
Use .find and combine with :last. This way you search the table for the last td
$t.find("td:last")
From jQuery docs:
Description: Get the descendants of each element in the current set of matched elements, filtered by a selector, jQuery object, or element.
Description: Selects the last matched element.
Note that :last selects a single element by filtering the current jQuery collection and matching the last element within it.
See working example here http://jsfiddle.net/MXjFP/2/
var $t = $("#mytable");
var $td = $t.find("td:last");
alert($td.html());
It's a little confusing and if at all possible I'd remove the '$' from your variable names to make it a little easier to read.