JavaScript Error - Invalid Property Value

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

Line of code:

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

IE 6/7/8:

Invalid property value

Thanks in advance!

+3
source share
3 answers

Does this code execute after the DOM is fully loaded? Perhaps there is no panel-hlisting-all yet? If you are using Prototype, you can 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 to test it on IE (fortunately / unfortunately), but what if you tried:

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

Added:

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

+2
source

JavaScript has no such thing as .style.background. Use .style.backgroundColor.

0

Since you are trying to set backgroundColorwhen you receive this error, I assume that a property whose value is not valid is backgroundColor!

Set a breakpoint on this line and find out what value matters color.

0
source

Source: https://habr.com/ru/post/1715257/


All Articles