Use the .children
collection to avoid the text node.
divvy.children[0].setAttribute("style", "color: violet;");
In modern browsers (like IE9+), you can use .firstElementChild
instead of .firstChild
.
divvy.firstElementChild.setAttribute("style", "color: violet;");
And off topic, but I wouldn't use setAttribute
to set the color. I'd use the .style
property.
divvy.firstElementChild.style.color = "violet";