set html text color and size using javascript
var elem = document.getElementById("MonitorInformation");
elem.innerHTML = "Setting different HTML content";
elem.style.color = "Red";
elem.style.fontSize = "large";
var myDiv = document.getElementById("MonitorInformation");
myDiv.style.fontSize = "11px";
myDiv.style.color = "blue";
Take a look at the JavaScript Style Attributes
I've abstracted a few methods, which could make them a little more useful for multiple invocations:
var el = document.getElementById("MonitorInformation");
function text( el, str ) {
if ( el.textContent ) {
el.textContent = str;
} else {
el.innerText = str;
}
}
function size ( el, str ) {
el.style.fontSize = str;
}
function color ( el, str ) {
el.style.color = str;
}
size( el, '11px')
color( el, 'red' )
text(el, 'Hello World')
Note: The best practice to dynamically change this type of stuff would be by setting the styles in a seperate external selector:
.message { color:red; font-size:1.1em; }
And toggling the class name, .className+= 'message' ( or an abstracted function to add/remove classes ).