Tengo 2 variables y necesito hacer esto como un color. Por ejemplo:
table1.style.cssText = "color: textcolor; background-color: bgcolor; "donde bgcolor y textcolor - variables con valor de color (rojo/negro por ejemplo)
Utilice un literal de plantilla.
table1.style.cssText = `color: ${textcolor}; background-color: ${bgcolor}; "Puede inyectar variables en una cadena usando una cadena literal de plantilla:
const textColor = 'white'; const bgColor = 'black'; table1.style.cssText = `color: ${textColor}; background-color: ${bgColor};`;Manifestación:
const msg = 'hello'; const msg2 = 'world'; console.log(`${msg} ${msg2}!!!`);También puede asignar los valores manualmente:
const textColor = 'white'; const bgColor = 'black'; table1.style.color = textColor; table1.style.backgroundColor = bgColor;