Set color of checkbox and its text to green if checked and red if it is checked

I want to set the color of checkbox and its text to green if it is checked and set to red if it is checked.
How to do that?
I know how to do that in CSS.
e.g.
<td><div class=‘red’><input type=“checkbox” name=“choice” value=“1” checked>Keyboard is Broken</div></td>
<td><div class=‘red’><input type=“checkbox” name=“choice” value=“2” checked>Ack</div></td>
<td><div class=‘green’><input type=“checkbox” name=“choice” value=“3” >Ok</div></td>
How to do that with javascript?

Use an onclick handler to change the class.