Remove background color from table cell

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    Remove background color from table cell

    Hi there,

    I'm using JavaScript to highlight a row or column in a table.
    I have created a CSS class that changes the background colour to a light blue and I apply this class to the cells in the selected row/column.

    It works great most of the time but sometimes the cell may have an inline style sets background colour to yellow. This, of course, overwrites the background colour in the class that is being used to highlight the cell.

    (Also, all of the cells contain at least one hyperlink and if the cell's background colour is set to yellow, this hyperlink's background colour is also set to yellow using an inline style)

    When applying the class to the cell I have attempted to remove the background color for the cell (and hyperlink) but this does not appear to work.

    Could someone please point out what I'm doing wrong:

    Code:
    function SelectColumn(colIndex)
    { Deselect(); //<----deselects any rows/columns selected
      var gridView = document.getElementById('myGridTable');
      var rows = gridView.getElementsByTagName('tr');
      for(i=0; i < rows.length; i++)
      {
         var cells = rows[i].getElementsByTagName('td');
         if(colIndex<cells.length)
         {
           cells[colIndex].className = cells[colIndex].className +' selectedRowOrColumn';
           cells[colIndex].style.backgroundcolor = '';
           var links = cells[colIndex].getElementsByTagName('a');
           for(linkIndex = 0; linkIndex < links.length; linkIndex++)
           {
               links[linkIndex].style.backgroundcolor = '';
           }
       } 
    }
    
    //......
    }

    Thanks

    -Frinny
    Last edited by Frinavale; Feb 2 '09, 03:15 PM. Reason: added additional information about hyperlinks in the table
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    The "C" in style.backgroun dColor is a capital one.

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      Thank you!

      It's working now.

      This just proves that developing with VB.NET has made me lazy.
      I didn't even think to look at the capitalization.

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        That's one of the first things to look out for. It also can't harm to be vigilant on cases in lenient languages too.

        Comment

        Working...