title: Change colour of td in dynamic table generated in php
body: <p>I'm creating a PHP script that will dynamically generate tr and td elements for a table. When the user clicks in a specific cell in the first column, an AJAX function executes to display additional content. This is working as it should, however, I'm having trouble with what should be simple styling. When the user clicks on a given cell, I want that row to change colour (works) until they click on another cell (doesn't work). </p>
  
  <p>Since my PHP file is rather large, I'm only posting the relevant parts. </p>
  
  <pre><code>&lt;?php
   $myFiles = showMyAttrs();
   foreach($myFiles as $myFile) {
  echo("&lt;tr class = 'gradeC' onClick = 'changeColour(this)' onchange = 'restoreColour(this)' &gt;");
  echo("&lt;td onClick = 'sendCell(this)' &gt;&lt;img src = $msEx /&gt;&lt;/td&gt;");
  echo("&lt;td&gt;$myFile&lt;/td&gt;");
  echo("&lt;/tr&gt;");
  }
  </code></pre>
  
  <p>I've also tried using onblur instead of onchange but that gave the same result. </p>
  
  <p>The Javascript functions:</p>
  
  <pre><code>function changeColour(z) {
    z.style.backgroundColor = "#FFFFFF";
  }
  
  function restoreColour(y) {
    y.style.backgroundColor = "#00FF00";
  }
  </code></pre>
  
  <p>Before I also tried:</p>
  
  <pre><code>function changeColour(z) {
    document.getElementsByTagName("tr").style.backgroundColor = "#00FF00";
    z.style.backgroundColor = "#FFFFFF";
    &lt;!-- document.getElementsByTagName("td").style.backgroundColor = "#00FF00"; --&gt;
  }
  
  function changeColour(z) {
    z.style.backgroundColor = "#FFFFFF";
    document.getElementsByTagName("tr").style.backgroundColor = "#00FF00";
  }
  
  $('tr').click(function() {
    $('tr').css('backgroundColor', '#0F0');
    $(this).css('backgroundColor', '#FFF');
  });
  </code></pre>
  
  <p>With each of them (except the last), the colour does change to white, however, when the user clicks on any other row, the previous row doesn't return to green. I don't mind if this works with Javascript or JQuery, as long as it is compatible across browsers. Even a fancy CSS trick I'm fine with using. </p>