I have 2 variables and i need to make this as a color. For example:
table1.style.cssText = "color: textcolor; background-color: bgcolor; "
where bgcolor and textcolor - variables with color value (red/black for example)
I have 2 variables and i need to make this as a color. For example:
table1.style.cssText = "color: textcolor; background-color: bgcolor; "
where bgcolor and textcolor - variables with color value (red/black for example)
Use a template literal.
table1.style.cssText = `color: ${textcolor}; background-color: ${bgcolor}; "
You can inject variables into a string using a template literal string:
const textColor = 'white';
const bgColor = 'black';
table1.style.cssText = `color: ${textColor}; background-color: ${bgColor};`;
Demo:
const msg = 'hello';
const msg2 = 'world';
console.log(`${msg} ${msg2}!!!`);
You could also assign the values manually:
const textColor = 'white';
const bgColor = 'black';
table1.style.color = textColor;
table1.style.backgroundColor = bgColor;