Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 277
Rohan Avatar asked Oct 26 '22 06:10

Rohan


1 Answers

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>
like image 79
Larsenal Avatar answered Nov 09 '22 08:11

Larsenal