Change text color with Javascript?
Solution 1:
You set the style per element and not by its content:
function init() {
document.getElementById("about").style.color = 'blue';
}
With innerHTML
you get/set the content of an element. So if you would want to modify your title, innerHTML
would be the way to go.
In your case, however, you just want to modify a property of the element (change the color of the text inside it), so you address the style
property of the element itself.
Solution 2:
use ONLY
function init() {
about = document.getElementById("about");
about.style.color = 'blue';
}
.innerHTML()
sets or gets the HTML syntax describing the element's descendants., All you need is an object here.
Demo