Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

166
Views
Hover keyframe values green and red

I'm kind of stuck in a keyframe. I have a table with values from a fetch (json) and i should add a hover when the values is less than 5 in red and starting from 5 in green. This is my code in javascript ->

how do i have to implement the keyframe with it in css or is it different that i think?

 // Html

 <div id="group3">
    <table class="table">
      <thead>
        <tr class="info">
          <th></th>
          <th>February</th>
          <th>March</th>
          <th>April</th>
          <th>May</th>
          <th>June</th>
          <th>July</th>
          <th>August</th>
        </tr>
      </thead>
      <tbody id='mytable'>
      </tbody>
    </table>
</div>

 //CSS
Keyframe?


 //hover

 let cells = document.querySelectorAll("tbody");
 cells.forEach( el => el.addEventListener('mouseenter', function () {
   if(el.textContent < 5){
     el.classList.add('underfive');
   } else if (el.textContent >=5){
     el.classList.add('abovefive');
   }
 }));

  // reset animationx
  cells.forEach(el => el.addEventListener('mouseleave', function () {
   if(el.textContent < 5){
     el.classList.remove('underfive');
   } else if (el.textContent >=5){
     el.classList.remove('abovefive');
   }
 }));

it should be like this ->

this is the startpage, background is white

this is the end result how it should be, uploaded from a json file in a table, red value

this is the green value when it's 5 of higher

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Based on what you say you want to show a different background color or styling in general than the default if the mouse is over the td.

So use :hover for that. You want to have a transition between those states so use transition.

You want to have a different color if it is above or below 5. So define what you want to have as default and add a class for the other case.

let data = [1,4,2,8,12,2,5,7];

const tr = document.querySelector('tr');
data.forEach(elem => {
   let td = document.createElement('td');
   td.textContent = elem;

   td.classList.toggle('belowfive', elem < 5);

   tr.appendChild(td);
});
td {
  transition: background-color 1s;
  background-color: white;
  padding: 1rem;
  border: 1px solid hsl(0 0% 50%);
}

td:hover {
   background-color: green;
}

td.belowfive:hover {
   background-color: red;
}
<table>
  <tbody>
     <tr>
     </tr>
  </tbody>
</table>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!