JQuery div on the fly with background color

I wonder if anyone can explain why in the first div created, the background color won't work and this happens 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 limitations?

+3


source to share


1 answer


You need to make the property the backgroundColor

key of the object css

.

$("<div/>", {
    width:300,
    height:400,
    css: {
        backgroundColor:"#425412"
    },
    text: "hello there"
}).appendTo("body");

      



jsFiddle .

+5


source







All Articles