使用<table>标记中的JavaScript更改CSS属性

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

Use

document.getElementById(x).style.backgroundColor="#4ead3a";

http://www.w3schools.com/jsref/prop_style_backgroundcolor.asp

Instead of

    document.getElementById(x).style.background-color="#4ead3a";

use

    document.getElementById(x).style.background="#4ead3a";

i've a suggestion for you. You can use

<div></div>

In this way:

<?php
for($i=1;$i<=$count;$i++)
{ ?>
<div id="<?php echo $i; ?>" style="width:50px;display:inline-table" onclick="changecolor(<?php echo i;?>)">
    <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="" >
<?php } ?>

And after that you can use jquery and do something like:

function changecolor(id){
$("#"+id).css({"background-color":"#4ead3a"});
}

Only to let you know, is deprecated, anyway in your code, you miss to call the I var on while for:

onclick="changecolor(<?php echo i;?>)">