Having looked at the docs on jquery css , if you want to apply these values ββin one call, you will need to create a valid json, According to the docs:
var validValues =
{
"background-color": "#ffe",
"border-left": "5px solid #ccc"
};
or
var validValues =
{
backgroundColor: "#ffe",
borderLeft: "5px solid #ccc"
}
then
$(selector).css(validValues);
Note that with DOM notes, quotation marks around property names are optional, but with a CSS notation, they are required due to a hyphen in the name
in particular, the reason your work is not working is the following: the correct json for jquery is not created:
var bgColor = "'background' : 'rgb(102,204,0)'";
var textColor = "'color' : 'rgb(40,40,40)'";
var json = {bgColor, textColor};
json =
{
bgColor: "'background' : 'rgb(102,204,0)'",
textColor: "'color' : 'rgb(40,40,40)'"
}