Reputation: 3
I have a table:
<table>
<thead>
<tr>
<td>col 1</td>
<td>col 2</td>
<td>col 3</td>
</tr>
</thead>
<tbody>
<tr>
<td>row 1</td>
<td class="editable">value 1</td>
<td class="editable">value 2</td>
</tr>
<tr>
<td>row 2</td>
<td class="editable">value 1</td>
<td class="editable">value 2</td>
</tr>
<tr>
<td>row 3</td>
<td class="editable">value 1</td>
<td class="editable">value 2</td>
</tr>
<tr>
<td>row 4</td>
<td class="editable">value 1</td>
<td class="editable">value 2</td>
</tr>
<tr>
<td>row 5</td>
<td class="editable">value 1</td>
<td class="editable">value 2</td>
</tr>
</tbody>
</table>
How can I select (using only CSS selectors) only one element from td.editable
? Analog of jQuery :first
selector will be acceptable.
Upvotes: 0
Views: 9457
Reputation: 14827
Not sure this is what you want but try this:
table > tbody > tr > td:nth-child(2) {
color: red;
}
Upvotes: 0
Reputation: 8379
Is this your only table of td.editable's? Try something like this...
td.editable:nth-child(2) //or 3 or 4, etc...
Upvotes: 0
Reputation: 1232
You could use an n-th child selector. Use one to get at the exact table row that you want, then use a second n-th child to get at the exact <td>
element you want.
For example if I wanted the second row, and the second <td>
element with a class="editable" I could do this:
tr:nth-child(2) > td.editable:nth-child(2)
Upvotes: 1
Reputation: 6947
On compatible browsers, you can use the :nth-child pseudo-class
Upvotes: 0