title: How can I create an automatically generated alteranate table row color?
body: <p>I've been trying to make this CSS code work:</p>
  
  <pre><code>table.mytable {
      margin: 0;
      padding: 0;
      border: 0;
      font-size: 0.8em;
      border-collapse: collapse;
  }
  table.mytable td, table.mytable th { 
      width: auto;
      padding: 2px 4px;
      vertical-align: top;
  }
  table.mytable th {
      color: #fff;
      background:url(images/header-bg.gif);
      text-align: left;
  }
  table.mytable tr.alternateColor {
      background-color:#E9F3FC;
  }
  </code></pre>
  
  <p>well, it works, if I do write it manually. But as the tables are going to be generated thru asp.NET (Aspx) , which is not manually created- I'd like my table to generate the alternate rows.
  I've been trying to make this work with Javascript, but I can't figure it out and I believe this is a good resource site.</p>
  
  <p>I've been using a manual table with Adobe Dreamweaver cs4 as a test, but I have to put the class of "alternatecolors" in order to make them appear, and I can't do this normally.:</p>
  
  <p>Question is , can someone provide me a good Javascript that I would put in the header of the file, and actually help me out to make this work ? I think I'm burned...or maybe I can't see what others see quickly due to the amount of time I've spent.</p>
  
  <p>I just tried posting the code of my table here, but I couldn't get it well formatted and I got to run... </p>
  
  <p>I'm not using an 'id' on this table, but the class is 'mytable'.</p>
  
  <p>Thank you so much for your good help.
  <strong>UPDATE: How to solve this question</strong>
  On the CSS file that defines the Tables, I had to add these two lines (of course there's more lines to define a good table) ..but these two are important</p>
  
  <pre><code>table.alternate td.odd { background-color:#fff}
  table.alternate td.even { background-color:#e6e6e6; }
  </code></pre>
  
  <p>and after that, I added these lines to the html, just before drawing a table.
  This is a Jquery thing that activates the odd and even properties of the tables</p>
  
  <pre><code>&lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script&gt;
  $(document).ready(function()
  {
    $("table.alternate tr:even td").addClass("even");
    $("table.alternate tr:odd td").addClass("odd");
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>If you find it helpful, please try it and if it doesn't work, it might be something else out of my knowledge. But this worked out fine in my case.</p>