Set bgcolor of a newly added table row?

M

Martin

I'm using the following function to insert a new row in a table. This
works fine - no problems. But, I would like to also set the background
color of the new row and I can't figure out how to do it.

I tried adding: Y.bgcolor='green'; after the Y.innerHTML = Msg1;
but that didn't work.

I tried adding:
document.getElementById('TableX').rows(1).bgcolor='green';
at the end of the funtion but that didn't work either.

Can someone give me a clue here?

Thanks

------------------------------------------------
function insRow(Msg1,Msg2)
{
var x=document.getElementById('TableX').insertRow(1);
var Y = x.insertCell(0);
var Z = x.insertCell(1);
Y.innerHTML = Msg1;
Z.innerHTML = Msg2;
}
 
K

kaeli

I'm using the following function to insert a new row in a table. This
works fine - no problems. But, I would like to also set the background
color of the new row and I can't figure out how to do it.

I tried adding: Y.bgcolor='green'; after the Y.innerHTML = Msg1;
but that didn't work.

That would be b/c the property name is Y.bgColor. Case-sensitive.
Or you can do Y.style.backgroundColor. That one works for more elements than
bgColor does, I think.

--
 
R

Rob B

Or...

Y.style.background

The CSS 'background' property is a catch-all for every
background-related attribute; the parser knows which is which by its
data format. Don't use 'bgColor', it's deprecated.

cheers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top