Jquery background color does not work

advertisements

guys I'm trying to set the backgroundColor of a draggable element through Jquery ".css()" function. The attribute backgroundColor actually change It's value, but somehow the color Itself don't change.

My code:

var $nDiv = $('<div></div>')
$nDiv.draggable();
var color = "rgba(120,120,120)";
canvas.append($nDiv);
$nDiv.css('backgroundColor',color);


You used the rgba directive so you are supposed to pass 4 values (r,g,b,a)

var $nDiv = $('<div></div>')
$nDiv.draggable();
var color = "rgba(120,120,120,1)";
canvas.append($nDiv);
$nDiv.css('backgroundColor',color);

If you just want to set the color and not the alpha make sure you use rgb()

var color = "rgb(120,120,120)";

Extra:

jQuery support both these notations: "backgroundColor" , "background-color"