title: Check if tr is an even or odd row to toggle background color in striped table
body: <p>I'm trying to toggle the background color of some <code>tr</code> elements based on the background color they are when clicked. This is simple when not working with a striped table. Essentially, the table starts out like the screenshot below. If I click on a row I want to change it to the green hex color I have in my if statement, and if I click it again I want to change it back to the color it was before initally being clicked.<a href="https://i.stack.imgur.com/KjUdN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KjUdN.png" alt="the table"></a></p>
  
  <p>Right now this will change any row that is clicked to the green color, but when clicked again it changes it to white regardless of what color it was before being clicked the first time:</p>
  
  <pre><code>onClick(message:DataTable, idx:any){
    var rowClicked = &lt;HTMLCanvasElement&gt; document.getElementById(message.tDataPoint);
    var rowColor = rowClicked.style.backgroundColor;
  if (idx%2===0 &amp;&amp; rowColor === "#015939"){
      rowClicked.style.backgroundColor="white";
      rowClicked.style.color="#015939";
  } else if (idx%2===1 &amp;&amp; rowColor === "#d3d3d3") {
    rowClicked.style.backgroundColor="#015939";
    rowClicked.style.color="white";
  } else if (idx%2===0 &amp;&amp; rowColor === "white") {
    rowClicked.style.backgroundColor="#015939";
    rowClicked.style.color="white";
  } else if (idx%2===1 &amp;&amp; rowColor === "#015939") {
    rowClicked.style.backgroundColor="#d3d3d3";
    rowClicked.style.color="#015939";
   }
  }
  </code></pre>
  
  <p>HTML to generate table:</p>
  
  <pre><code>&lt;tr *ngFor="let dPoint of theData; let idx=index" (click)="onClick(dPoint, idx)" (row)="received($event)" id="{{dPoint.tDataPoint}}"&gt;
      &lt;td&gt;{{dPoint.tDataPoint}}&lt;/td&gt;
      &lt;td&gt;{{dPoint.tICCP}}&lt;/td&gt;
      &lt;td&gt;{{dPoint.tStartDate}}&lt;/td&gt;
      &lt;td&gt;{{dPoint.tEndDate}}&lt;/td&gt;
  &lt;/tr&gt;
  </code></pre>
  
  <p>If there's a way in Typescript to check if the row is even or odd, then I can just write the proper if statement's to change the color based on that.</p>
  
  <p><strong>UPDATE</strong> I edited my function</p>