samedi 10 octobre 2015

Highlight label if checkbox is checked in a table

Please don't mark it as a duplicate. I saw the solution given here. But it's not working for me.

I want to change the label color red if the checkbox is checked. But the problem is that my checkbox and label are in different td.

<tr>
    <td><input type="checkbox" name="ids[]" id="id-1" value="1"></td>
    <td><label for="id-1">Label 1 Name</label></td>
</tr>
<tr>
    <td><input type="checkbox" name="ids[]" id="id-2" value="2"></td>
    <td><label for="id-2">Label 2 Name</label></td>
</tr>
<tr>
    <td><input type="checkbox" name="ids[]" id="id-3" value="3"></td>
    <td><label for="id-3">Label 3 Name</label></td>
</tr>

If both the checkbox and label are in same td the following css works fine

input[type=checkbox]:checked + label{
    color: red;
}

But in different td it's not working.

I want to do this with css.




Aucun commentaire:

Enregistrer un commentaire