How do I assign a style to every first cell of every row in a table?
$("#myTable tr td:first").addClass("black");
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use the
:first-childpseudo class instead of:first.The
:firstpseudo class actually selects the first element that was returned in your list. For example,$('div span:first')would return only the very first span under the first div that happened to be returned.The
:first-childpseudo class selects the first element under a particular parent, but returns as many elements as there are first children. For example,$('table tr td:first-child')returns the first cell of every single row.When you used
:first, it was returning only the first cell of the first row that happened to be selected.For more information, consult the jQuery documentation: