Forum Moderators: open

Message Too Old, No Replies

IE backgroundColor Manipulation

         

doron_bl

10:14 am on Apr 10, 2005 (gmt 0)

10+ Year Member



Hi all,
I have a table which I try to mark and un-mark its rows.
I'm trying to mark each of the table's cells with respect to the cell's original color.

Here is my code:

function mark_tr(row_id, col_num){
var row = parseInt(row_id.id.split('_')[1] ) + 1;

var cell;
var bgcolor;

for(var col = 0; col < 1; col++) {
cell = document.getElementById("a" + row.toString() + "#" + (col).toString());
style = cell.getAttribute('style');
bgcolor = style.getAttribute("backgroundColor");

bgcolor = bgcolor.replace('#',"");
bgcolor = parseInt(bgcolor, 16) * 8;
bgcolor = bgcolor.toString(16); // I tried also "#" + bgcolor.toString(16);

// To this spot every thing is good
try {
// This line seems not to do what I want it to do
// There is no exception in this line
cell.style.setAttribute('backgroundColor', bgcolor);

} catch(e) { alert('Exception:\n' + e); alert('\nbgcolor:\n' + bgcolor);}

style = cell.getAttribute('style');
bgcolor = style.getAttribute("backgroundColor");

// bgcolor has not been changed at all!
alert(bgcolor);
}

This code does not work. I have also tried meny othere ways to set the color but without success.

Does anybody knows how to solve this problem?

Thanks,

Greven

2:47 pm on Apr 10, 2005 (gmt 0)

10+ Year Member



Now, all I know about is working in IE(unfortunately), but I beleive instead of cell.style.setAttribute('backgroundColor', bgcolor); you may be able to just use cell.style.backgroundColor = bgcolor;. If this is not working, you could always try doing an alert on bgcolor to make sure the value is valid. Hope that helps.

doron_bl

6:59 am on Apr 11, 2005 (gmt 0)

10+ Year Member



I have already tried this and I get an exception on this.
It works fine only if I assign it directly wioth value, but not a value which I manipulated befor!

More Ideas?

Bernard Marx

8:31 am on Apr 11, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



How are the cells assigned a colour initially?
Is it via stylesheet?
(In which case, it can't work, because stylesheet values don't appear on the element's own style object)