title: Changing background color of HTML Table cell after Javascript Changes it
body: <p>I have an HTML table that outputs like this: (It's manually built in HTML and styled with CSS via classes <code>rowStyle1</code> and <code>rowStyle2</code>)</p>
  <p><a href="https://i.stack.imgur.com/1OoRM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1OoRM.png" alt="enter image description here" /></a></p>
  <p>When the user clicks the buttons for next week or previous week, the page loads a schedule and, if there is any datapoint to load into the table, it both puts the text in the cell and changes the background color with this code:</p>
  <pre><code> document.getElementById(cellID).innerText = parsed.title
   document.getElementById(cellID).style.backgroundColor = &quot;#cc00cc&quot;
  </code></pre>
  <p>The problem is, when the user wants to change weeks, the table should be &quot;cleared out&quot;, and made ready for the new data. That doesn't happen even though I put this code at the beginning of the function that triggers when either button is pressed:</p>
  <pre><code>let cells = document.getElementsByClassName(&quot;rowStyle1&quot;)
  
  for (let i = 0; i &lt; cells.length; i++) {
      cells[i].style.backgroundColor = &quot;#ffffff&quot;
  }
  
  let cells2 = document.getElementsByClassName(&quot;rowStyle2&quot;)
  
  for (let i = 0; i &lt; cells2.length; i++) {
      cells2[i].style.backgroundColor = &quot;#d8ebfa&quot;
  }
  </code></pre>
  <p>I know this code works, because I can change the colors of the cells when the page first loads using this code, but it still leaves a colored cell left over when I change weeks:</p>
  <p><a href="https://i.stack.imgur.com/2ezqK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2ezqK.png" alt="enter image description here" /></a></p>
  <p>How do I change the color of the cell back so I can &quot;reset&quot; the table to get ready for the new data? Does it have something to do with setting the color via javascript?</p>
  <p>(BTW, this whole code has been written in native HTML, CSS, and JavaScript, so any solutions that don't involve any plug-ins would be greatly appreciated!)</p>