I am developing an online quiz application and it provides a list of all the questions and when a user clicks a question number, the respective question should be shown. When a user clicks on any question number, the question numbered cell's background color should be changed. For this my JS is as follows
<script>
function changecolor(x)
{
document.getElementById(x).style.background-color="#4ead3a";
}
</script>
and the table
code is as follows:
<table border=1>
<tr>
<?php
for($i=1;$i<=$count;$i++)
{ ?>
<td id="<?php echo $i; ?> " align="center" style="width:50px" onclick="changecolor(id)" >
<a href="http://127.0.0.1/example/runquiz.php?x=<?php echo $i; ?>" ><?php echo $i; ?> </a>
<input type="hidden" name=<?php echo $i; ?> value="" >
</td>
<?php }
?>
</tr></table>
and the css is as follows
td{
vertical-align:middle;
background-color:#dbd6d2;
border:1px solid #000000;
border-width:0px 1px 1px 0px;
text-align:center;
padding:7px;
font-size:10px;
font-family:Arial;
font-weight:bold;
color:#000000;
}
But when I click on any cell, the background color is remaining the same. I am new to use CSS with JS. Please help me. Thanks in advance