0

What I am trying to do is have something like this

var myVar = "blue"

then do

document.body.style.color = myVar

so the color of body is blue.

Could anyone help me?

5
  • 1
    This should be done in CSS. Why are you using JS? (Just curious) Commented May 16, 2016 at 22:10
  • @MichaelSchwartz what i want to do is be able to use text strings to add parts of hex codes together then use it as one whole hex code, for example, var myVar = #2b + 3a + 5d Commented May 16, 2016 at 23:16
  • Are the hex codes being randomly generated? Commented May 16, 2016 at 23:28
  • @MichaelSchwartz there will be a mixture of random generation and user input Commented May 16, 2016 at 23:37
  • 1
    I see JS abused a lot because of convenience. So I thought I'd ask why. That makes perfect sense. Commented May 16, 2016 at 23:40

1 Answer 1

7

That will work to make the text blue. If you wanted to change the background color use backgroundColor

document.body.style.backgroundColor = myVar;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.