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
0
points

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 about 6 years ago by danwellman
0
points

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

Answered about 6 years ago by Paul Gueller