nanjero05 nanjero05 - 9 months ago 36
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:


did you try these methods?

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


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