I'm trying to change the text color of the radio button when I lose the selection. It happens that these radio buttons are in several tables. The rule is as follows: The screen will be loaded with some one radio button selected per table. When the client selects another radio button, the text of the radio button should be red. So far, okay. The problem is when to return the original selection, the color of this should return to black without affecting the text of the other radio buttons. Here is my code:
<div id="div1">
<table class="table table-hover table-bordered">
<tbody>
<tr>
<td class="col-md-2"><input type="radio" name="ans" value="0"><label>Dog</label></td>
<td class="col-md-2"><input type="radio" name="ans" value="1" checked="checked"><label>Horse</label></td>
<td class="col-md-2"><input type="radio" name="ans" value="2"><label>Cat</label></td>
</tr>
</tbody>
</table>
</div>
<div id="div2">
<table class="table table-hover table-bordered">
<tbody>
<tr>
<td class="col-md-2"><input type="radio" name="ans2" value="3"><label>Bird</label></td>
<td class="col-md-2"><input type="radio" name="ans2" value="4"><label>Fish</label></td>
<td class="col-md-2"><input type="radio" name="ans2" value="5" checked="checked"><label>Frog</label></td>
</tr>
</tbody>
</table>
</div>
<div id="div3">
<table class="table table-hover table-bordered">
<tbody>
<tr>
<td class="col-md-2"><input type="radio" name="ans3" value="6" checked="checked"><label>Lion</label></td>
<td class="col-md-2"><input type="radio" name="ans3" value="7"><label>Panther</label></td>
<td class="col-md-2"><input type="radio" name="ans3" value="8"><label>Tiger</label></td>
</tr>
</tbody>
</table>
</div>
Jquery:
<script>
var arrayInputs = $('input:radio');
var arrayChecked = $('input:checked');
arrayInputs.change(function() {
var result = $.inArray(this, arrayChecked);
//$('label').css('color','#000');
if(result < 0)
$(this).next('label').css("color", "red");
});