I have a simple table of HTML options:
<table>
<tr>
<td>blue</td>
<td>green</td>
</tr>
<tr>
<td>red</td>
<td>cream</td>
</tr>
</table>
CSS with related styles:
td { background-color: #FFF; border: 1px solid #3F3F3F; cursor: pointer; }
td.selected { color: #D93A2C; border: 1px solid #D93A2C; }
It looks like:

When I click on one of the cells in the table, I want the border and text to be red. Therefore, I use jQuery to switch the .selected class using the following code.
$('td').each(function(){
$(this).click(function(){
$(this).toggleClass('selected');
});
});
However, the result is the following:

The first cell of the table (blue) is the only one that looks the way I want it when it is selected. I need to select all the borders of the selected cell.
Any ideas on how to achieve this? I don't mind splitting tables if someone can suggest a better way.
source
share