Three things spring to mind:
- You're using the
:last
pseudo-element. That will match at most one element total, in this case the very last table cell in "stocktable". Do you perhaps mean :last-child
instead?
- You're using
:eq(2)
which will match the third element in the entire set only. Do you perhaps mean :nth-child(2)
?
$("#stocktable tr td.eq(2)).addClass...
is missing and end quote; and
- There is nothing wrong with what you're doing. What precisely isn't working? Perhaps it's not formatting that can be applied to a table cell.
To further explain (1) imagine you have a table with 3 rows of 4 cells with an id of "mytable". This code:
$("#mytable td:eq(2)").css("background", "yellow");
will colour the third element of the first row (:eq()
is zero-based) whereas:
$("#mytable td:nth-child(2)").css("background", "yellow");
will colour the second cell in each row.
$("#mytable td:last").css("background", "yellow");
will colour the very last cell in the very last row but:
$("#mytable td:last-child").css("background", "yellow");
will colour the last cell in each row.