Use the :first-child pseudo-class instead of :first .
$("#myTable tr td:first-child").addClass("black");
The :first pseudo-class actually selects the first item that was returned in your list. For example, $('div span:first') will return only the very first run under the first div that was returned.
The :first-child pseudo :first-child selects the first element under a specific parent, but returns as many elements as there are first children. For example, $('table tr td:first-child') returns the first cell of each individual row.
When you used :first , it returned only the first cell of the first row that was selected.
See the jQuery documentation for more information:
Devin Burke May 27 '11 at 16:45 2011-05-27 16:45
source share