MattE
MattE

Reputation: 159

To set colour using javascript for specific column cell conditionally

I have this javascript below and I'm trying to set the colour of the value in the cell conditionally to the same colour as the background of that column if it is equal to 0:

$(function(){
  var columnindex = $('th:contains("Q1 Spells")').index();

if(columnindex != -1)
  {
      $('tr').each(function() {
          var column = $('td', this).eq(columnindex);

          switch (column.text())
          {
              default:
                  column.css({backgroundColor: '#FF0000'});
                  if(column.value === 0) {
                      column.css({color: '#FF0000'});
                  }
                  break;
          }
      });
  }
)};

I can't seem to get this to work for the cell colour (background setting works fine) - How do I achieve this?

Upvotes: 0

Views: 77

Answers (1)

Alexander Higgins
Alexander Higgins

Reputation: 6905

try:

if(columnindex === 0) {
    column.css("color", "#FF0000");
}

If that doesn't work check to see if you have a CSS declaration overriding it somewhere, such as with !important.

Also verify there isn't a child HTML element whose style is overriding the column's css color.

Upvotes: 3

Related Questions