[...] I was thinking about something like:It is not correct at all. The `style' property is specified to be read-only:
var style1 = {
backgroundColor:"blue",
color:"white"
}
var myDiv = document.createElement("div");
myDiv.style = style1;
The question is how correct that is
<http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-ElementCSSInlineStyle>
and/or is there a better way to do it?if (myDiv)
{
for (var p in style1)
{
if (typeof myDiv.style[p] != "undefined")
{
myDiv.style[p] = style1[p];
}
}
}
See <http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSS2Properties>.
PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee