In this example Chrome sets the background red, firefox and IE do not.
Trying:
document.getElementById("firefoxDiv").style['backgroundColor'] = "Red";
and
document.getElementById("firefoxDiv").style['background-color'] = "Red";
I would much rather be able to use the same syntax used in external CSS
background-color
vs inline using javascript .style.backgroundColor =
Thanks for your help!
Note: NO jQuery please.
In this example Chrome sets the background red, firefox and IE do not.
Trying:
document.getElementById("firefoxDiv").style['backgroundColor'] = "Red";
and
document.getElementById("firefoxDiv").style['background-color'] = "Red";
I would much rather be able to use the same syntax used in external CSS
background-color
vs inline using javascript .style.backgroundColor =
Thanks for your help!
Note: NO jQuery please.
Share Improve this question edited Sep 4, 2012 at 22:41 Zoltan Toth 47.7k12 gold badges131 silver badges138 bronze badges asked Sep 4, 2012 at 22:36 Dan W.Dan W. 631 silver badge7 bronze badges 1- 1 @ZoltanToth I'm confused as to if you've read the question? – jeremy Commented Sep 4, 2012 at 22:43
1 Answer
Reset to default 9Use .style.setProperty(propertyName, value [, priority])
instead of an expando property.
Example:
document.getElementById("firefoxDiv").style.setProperty('background-color', 'red');