function cross() {
var dik = document.getElementsByName('r1c1')[0].parentNode;
dik.style.color = "red";
}
<table>
<tr>
<td><input type="radio" name="r1c1" value="TRUE"></td>
<td><input type="radio" name="r1c1" value="FALSE"></td>
</tr>
<tr>
<td><input type="radio" name="r1c2" value="TRUE"></td>
<td><input type="radio" name="r1c2" value="FALSE"></td>
</tr>
<input type="button" name="sbmt" value="CHECK" onclick="cross();">
</table>
When i click the button , I want to change color of td block to red that contains
input element <input type="radio" name="r1c1" value="TRUE">
You have to use property backgroundColor to change the color of td. color is used to change the color of the text
Read Here color vs backgroundColor
<script type="text/javascript">
function cross(){
var dik = document.getElementsByName('r1c1')[0].parentNode;
dik.style.backgroundColor = "red";
}
</script>
<table>
<tr>
<td><input type="radio" name="r1c1" value="TRUE"></td>
<td><input type="radio" name="r1c1" value="FALSE"></td>
</tr>
<tr>
<td><input type="radio" name="r1c2" value="TRUE"></td>
<td><input type="radio" name="r1c2" value="FALSE"></td>
</tr>
<input type="button" name="sbmt" value="CHECK" onclick="cross();">
</table>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With