jQuery div on the fly with background color
background-color, html, jquery, properties
Solution
You need to make the `backgroundColor` property a key of a `css` object.
$("<div/>", {
width:300,
height:400,
css: {
backgroundColor:"#425412"
},
text: "hello there"
}).appendTo("body");
jsFiddle.
Problem
I wonder if anybody can explain why in the first created div the background color will not work and it does in the second example. ``` $("<div/>", { width:300, height:400, backgroundColor:"#425412", //background-color does not work text: "hello there" }).appendTo("body"); ``` Note: without the background-color property the div will be created. ``` // works as defined including background-color $("<div style='width:300; height:400; background-color:#425412;'>hello there</div>").appendTo("body"); ``` Does the first method have restrictions?