nanjero05 nanjero05 - 1 year ago 76
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:

Answer Source

did you try these methods?

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


document.getElementById("errorsSpace").style.color = "red";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download