3

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?

Evik James
  • 10,335
  • 18
  • 71
  • 122
  • I think you are looking for the `or selector`. http://stackoverflow.com/questions/2263975/jquery-or-selector – SunnyRed Nov 28 '11 at 19:55

2 Answers2

10
$("tr:first").children("td:first, td:last").css("background", "yellow");
Johan
  • 3,202
  • 1
  • 23
  • 19
1

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/ ).

Jasper
  • 75,717
  • 14
  • 151
  • 146