Hi, im having a problem changing font with javascript. I tried doing this :

document.getElementById("answer").style.color = 'white'

it just doesn't work. Can somebody help me?

2 answers

danwellman 5600

Where are you running this script? In the head of the page, or the body?

If in the head, try moving the script element to the bottom of the body (just before the closing </body>), or use an onload handler attached to the body so that the code is not executed until after the element you're trying to set the color of has loaded

Answered over 6 years ago by danwellman

Additionally, it is better to use CSS to define the appearance of an element, and then change classnames with JavaScript.

Answered over 6 years ago by Paul Gueller