views:

128

answers:

3

Using IE 6/7/8, I receive a JavaScript error code.

The line of code is:

document.getElementById('all').style.backgroundColor = color;

The IE 6/7/8 is:

Invalid property value

Thanks in advance!

+1  A: 

Are you running this code after the DOM is completely loaded? Perhaps there is no 'panel-hlisting-all' yet? If you're using Prototype, you might try:

document.observe("dom:loaded", function() { // Wait until everything is loaded.
   document.getElementById('panel-hlisting-all').style.background = color;
 });

Just a thought — and I have no way of testing it on IE (thankfully/unfortunately), but what if you tried:

document.getElementById('panel-hlisting-all').style.backgroundColor = color;

Added:

Also note that color must be a string containing a valid CSS color (#FFFFFF, rgb(255,255,255), rgba(255,255,255,1)).

arbales
I just read the JQuery comment — although not being dependant on a library has it's advantages, Event handling and Selection from API's offer predictable and often dependable results across browsers.
arbales
I changed to backgroundColor = now I receive the error: "invalid property value". Any ideas? Thanks
GeorgeG
What is the value you have for that variable?
Noon Silk
I'd ensure that it is a string. If you're using HEX colors, check to make sure that you didn't leave out the '#'
arbales
A: 

There no such thing as .style.background in JavaScript. Use .style.backgroundColor.

Randell
I changed to backgroundColor - now I receive the error: "invalid property value". Any ideas? Thanks
GeorgeG
What's the value of the 'color' variable?
Randell
A: 

Since you're trying to set the backgroundColor when you get this error, my guess would be that the property whose value is invalid - is backgroundColor!

Set a breakpoint on that line and find out what value color has.

John Saunders