469,330 Members | 1,299 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,330 developers. It's quick & easy.

Remove background color from table cell

Frinavale
9,735 Expert Mod 8TB
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:

Expand|Select|Wrap|Line Numbers
  1. function SelectColumn(colIndex)
  2. { Deselect(); //<----deselects any rows/columns selected
  3.   var gridView = document.getElementById('myGridTable');
  4.   var rows = gridView.getElementsByTagName('tr');
  5.   for(i=0; i < rows.length; i++)
  6.   {
  7.      var cells = rows[i].getElementsByTagName('td');
  8.      if(colIndex<cells.length)
  9.      {
  10.        cells[colIndex].className = cells[colIndex].className +' selectedRowOrColumn';
  11.        cells[colIndex].style.backgroundcolor = '';
  12.        var links = cells[colIndex].getElementsByTagName('a');
  13.        for(linkIndex = 0; linkIndex < links.length; linkIndex++)
  14.        {
  15.            links[linkIndex].style.backgroundcolor = '';
  16.        }
  17.    } 
  18. }
  19.  
  20. //......
  21. }

Thanks

-Frinny
Feb 2 '09 #1
3 9779
acoder
16,027 Expert Mod 8TB
The "C" in style.backgroundColor is a capital one.
Feb 2 '09 #2
Frinavale
9,735 Expert Mod 8TB
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.
Feb 2 '09 #3
acoder
16,027 Expert Mod 8TB
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.
Feb 2 '09 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

7 posts views Thread by John A. | last post: by
5 posts views Thread by Greg N. | last post: by
1 post views Thread by Thanks | last post: by
5 posts views Thread by Michael | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.