Can I make a table cell have a different background color if the value =< a particular number with jquery or PHP?

前端 未结 5 499
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-28 17:31

I have an HTML table with a lot of numbers.

Is it possible to have a table cell change background color if the value inside that cell (or column) equals or is less than

5条回答
  •  粉色の甜心
    2021-01-28 18:28

    Here's an example of how to do it with JS/Jquery

    $("#Yourtable td").each( function() {
         var thisCell = $(this);
         var cellValue = parseInt(thisCell.text());
    
         if (!isNaN(cellValue) && (cellValue <=3000)) {
             thisCell.css("background-color","#FF0000");
          }
      }
     )
    

提交回复
热议问题