I need to select a table cell if the previous cell has a checked input. the I have a sneaking suspicion that this is not possible with CSS, can anybody confirm?
Here is an example:
<table>
<tr>
<td>Row with checked input</td>
<td><input type=checkbox checked /></td>
<td>should show.</td>
</tr>
<tr>
<td>Row with unchecked input</td>
<td><input type=checkbox /></td>
<td>should be hidden.</td>
</tr>
</table>
And the CSS I tried:
td:last-child { display:none; }
input:checked ~ td:last-child { display:initial; }
The first selector works to hide unchecked inputs, but then the second selector cannot make the input show up again. I assume the ~
combinator cannot handle children of previous siblings. Is there any way to get around this using CSS, or do I need to use some JavaScript solution?
JSFiddle for those who want a live scratchpad.