title: How to change background color of cell in table using java script
body: <p>I need to change background color of single cell in table using java script. </p>
  
  <p>During document i need style of all cell should be same ( so used style sheet to add this. ) , but on button click i need to change color of first cell.</p>
  
  <p>following is the sample code</p>
  
  <pre><code>&lt;html lang="en"&gt;
    &lt;head&gt;    
      &lt;script type="text/javascript" &gt;        
  
      function btnClick()
      {
              var x = document.getElementById("mytable").cells;
              x[0].innerHTML = "i want to change my cell color";
              x[0].bgColor = "Yellow";            
      }
      &lt;/script&gt;   
  &lt;/head&gt;
      &lt;style&gt;
      div
      {
      text-align: left; 
      text-indent: 0px; 
      padding: 0px 0px 0px 0px; 
      margin: 0px 0px 0px 0px;
      }
      td.td
      {
                   border-width : 1px; 
                   background-color: #99cc00;
                   text-align:center;
  
      }
      &lt;/style&gt;  
    &lt;body&gt;
    &lt;div&gt;  
      &lt;table id = "mytable" width="100%" border="1" cellpadding="2" cellspacing="2" style="background-color: #ffffff;"&gt;
        &lt;tr valign="top"&gt;
        &lt;td class = "td"&gt;&lt;br /&gt;  &lt;/td&gt;
        &lt;td class = "td"&gt;&lt;br /&gt;  &lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr valign="top"&gt;
        &lt;td class = "td"&gt;&lt;br /&gt;  &lt;/td&gt;
        &lt;td class = "td"&gt;&lt;br /&gt;  &lt;/td&gt;
        &lt;/tr&gt;
      &lt;/table&gt;
    &lt;/div&gt;
        &lt;input type="button" value="Click" OnClick = "btnClick()"&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>