Reputation: 10483
I am using jQuery 1.6.2
I am trying to turn the first and last cells of a table yellow.
Basically, I am using two lines of code to accomplish this.
$("tr:first").children("td:first").css("background", "yellow");
$("tr:first").children("td:last").css("background", "yellow");
How can I combine the two filters together to get the first and last tds in a row?
Upvotes: 3
Views: 1509
Reputation: 76003
In jQuery you can use multiple selectors at once by separating them with a comma:
$("tr:first").children("td:first, td:last").css("background", "yellow");
Here is the jQuery documentation for "Multiple Selectors": http://api.jquery.com/multiple-selector/
For a general note, jQuery uses the Sizzle Selction Engine which bases it's syntax off of CSS syntax ( http://sizzlejs.com/ ).
Upvotes: 1
Reputation: 3212
$("tr:first").children("td:first, td:last").css("background", "yellow");
Upvotes: 10