nanjero05 nanjero05 - 7 months ago 24
HTML Question

CSS - How can I set the color of strings written using "innerHTML" into a div

I currently have a function that outputs an array of strings into an html page. How can I set the color of the output text? This is the code that writes into a page:

function showErrors() {
if (errList.length >= 1)
document.getElementById("errorsSpace").innerHTML = errList.join('<br/>');
}


Ive tried using "color: red" with no luck. I get an error that says "Cannot set property 'innerHTML' of null"

here is a jsfiddle for the rest of the code: https://jsfiddle.net/wd6fpgm6/

Answer

did you try these methods?

document.getElementById("errorsSpace").setAttribute("style", "color:red");

or

document.getElementById("errorsSpace").style.color = "red";