title: Change tr background color based on conditionals thymeleaf
body: <p>I am looking to change a table row's background color based on an th:if conditional.</p>
  
  <p>For example: if expected != actual, bg = red. vice versa, bg = green.</p>
  
  <p>For my example, I currently have three columns -- eval type, expected, and actual. The evaluation type determines the the values for expected and actual. The current span <code>th:style</code> highlights correctly the individual cells, but I am looking to have the entire <code>&lt;tr&gt;</code> highlighted red or green based on the evaluation.</p>
  
  <p>Current code:</p>
  
  <pre><code>&lt;thead&gt; 
      &lt;th&gt;Eval Type &lt;/th&gt;
      &lt;th&gt;Expected &lt;/th&gt;
      &lt;th&gt;Actual &lt;/th&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
  &lt;tr&gt;
      &lt;td&gt;
                      &lt;span th:if="${example.getEvaluationType()} == '1'" th:text="${example.getExpectedcount()}" 
                      th:style="${example.getActualcount()} == ${example.getExpectedcount()} ? 'background: green' : 'background: red'"&gt;&lt;/span&gt;
  
                      &lt;span th:if="${example.getEvaluationType()} == '2'" th:text="${example.getExpectedmb()}"
                      th:style="${example.getActualmb()} == ${example.getExpectedmb()} ? 'background: green' : 'background: red'"&gt;&lt;/span&gt;
  
                      &lt;span th:if="${example.getEvaluationType()} == '3'" th:text="${example.getExpectedminutes()}" 
                      th:style="${example.getActualminutes()} == ${example.getExpectedminutes()} ? 'background: green' : 'background: red'" &gt;&lt;/span&gt;
      &lt;/td&gt;
  &lt;/tr&gt;
  &lt;/tbody&gt;
  </code></pre>
  
  <p>Appreciate any help or leads with related questions as I have not found any.
  Thanks!</p>