IE, appendChild, setAttribute, CSS Class

I want to add a star to the end of a label for mandatory fields in the DOM.

.mandatoryIndicator { font-color: red; }

 

var star = document.createElement("span");
star.setAttribute("class","mandatoryIndicator");
star.innerHTML = " *";
label.appendChild( star );

The above code doesn't work in IE, the star is added, but it remains the default text colour.

I did a bit of hunting around and found out the problem is actually with setAttribute.  It doesn't work with half a dozen properties on the element.

The fix is actually quite easy, use this:

var star = document.createElement("span");
star.className = "mandatoryIndicator";
star.innerHTML = " *";
label.appendChild( star );