0
<script>
$(document).ready(function() {
var refreshId = setInterval(function() {
if ($('#recent td') > '200') {.css("background-color", "#1eff00")};
},1000);
});
</script>

The above is what i'm trying to achieve but its definitely not working!
I have a table being outputted by PHP from a MySQL Db but i need to highlight a cell if the value is above 200 (or any value) is this possible with jQuery? #recent is the table id!

Thanks

2
Contributors
6
Replies
7
Views
7 Years
Discussion Span
Last Post by benhowdle89
0

Of course it is possible. You need to use .text() or .html() to get to the table cell value. Comparing a selector to a value won't work.

0

Cool,

With the my code i pasted in, where would i need to make the changes?

Thanks

0
<script type="text/javascript">
$(document).ready(function() {
var refreshId = setInterval(function() {

$("#recent tr").each(function() {
var tempresult = $("td").text();
});
if (tempresult < 200)
{
$("td").css("background-color", "red")
};

},1000);
});
</script>

Ok i read that link you gave, i've tried the code above but it's not working, does this look right to you?

0
$(document).ready(function() {
  $("#recent td").each(function () {
    if ($(this).text() > 100)
      $(this).css("background-color", "green");
  });
});

Edited by pritaeas: n/a

0

Thanks for that, i went with the below in the end, works great!

<script type="text/javascript">
$(document).ready(function() {
var refreshId = setInterval(function() {

         $("#recent tr:not(:first)").each(function() { 
             
             var tempresult = $(this).find("td:nth-child(3)").text();
             var setpoint = 200;
             
             if (tempresult < setpoint){
                 //change the color of the text to green if its a positive number
                 $(this).find("td:nth-child(3)").css("background-color", "#00FF00");
             }
             else if(tempresult > setpoint){
                 //change the color of the text to red if its a negatice number
                 $(this).find("td:nth-child(3)").css("background-color", "#FF0000");
				 $(this).find("td:nth-child(3)").css("color", "white");
             }
         });

},1000);
});
</script>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.