Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

155
Views
How to write this sentence correct JS

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)

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Use a template literal.

table1.style.cssText = `color: ${textcolor}; background-color: ${bgcolor}; "
about 4 years ago · Juan Pablo Isaza Report

0

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}!!!`);

about 4 years ago · Juan Pablo Isaza Report

0

You could also assign the values manually:

const textColor = 'white';
const bgColor = 'black';

table1.style.color = textColor;
table1.style.backgroundColor = bgColor;
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!