OL Learn

Changing text colour in a table

I am trying to change the text colour of individual cells in a table, based on the cell values using this code

if (field == "210299") {
  results.css({'color':'red'});
  }

The code works in that the colour is changed. But is also changed for all the other items in that column. If I apply multiple colours to different cell, the last one applied seems to override all the others, including cells which had no colour applied.
I don’t know what I’m doing, but this isn’t what I expected. Any suggestions please.

The behaviour is exactly what you have coded. Your script is applied to all <TD> inside your table.

You could change the color in a Post-Pagination script. This way, it will only apply to

that have the text value ‘210299’

You are changing the color for the entire column ( through the results.css() method). What you want is to specifically target the current cell, which is what the this object represents inside the .each() method.
So replace the results.css() statement with:

this.css({"color":"red"});

Thanks Phil
I have to keep typing until this post is > 20 characters long :grinning: