Onclick change of a cell background color

MissJones
MissJones used Ask the Experts™
on
I'd like to change the background of a cell color from white to blue (#000080) by onclick. How do I refer to the specific cell? The table data is dynamic.

thnx
MissJones
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
specify an id to the table.
You can access as,
tableName.rows(rowNum).cells(cellNo).style.backgrounColor = "#000080"



Example,

<HTML>
<HEAD>
</HEAD>
<BODY>

<table id="tabInsert">
     <tr>
          <td onclick="changeColor(this)">Sample</td>
     </tr>
</table>

</BODY>
<script language="javascript">
    function changeColor(obj)
     {
          obj.style.backgroundColor = "#000080";

          //if you cannot give the function try the below one

          tabInsert.rows[0].cells[0].style.backgroundColor = "#000080";

     }
</script>
</HTML>

Author

Commented:
That was great thnx.
you made my day :)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial