How do I change HTML table cell color on click
I'm trying to change the background color of an HTML table cell when the user clicks on the cell. Any ideas on how to do this? I have access to the JS Prototype library, so any suggestions for Prototype or straight Javascript would be welcome. Ugly, but demonstrates the effect: <table> <tr> <td onclick="this.style.backgroundColor = 'Red';">Sample</td> <td onclick="this.style.backgroundColor = 'Blue';">Data</td> </tr> </table> I'm not well versed in the Prototype framework, but here's some raw Javascript that'll do what you're looking for: var table = document.getElementsByTagName('table')[0];