I have this code:
You're looking for the style property on the element, there is no background-color
attribute:
document.getElementById("pic1").style.backgroundColor = "red";
That said, generally best to style things with CSS and add/remove classes.
T.J. Crowder beat me to it, but just as a demo, if you were hellbent on using setAttribute
, you could do so like this:
document.getElementById("pic1").setAttribute("style","background-color:red");
As you see, the css attribute is background-color, not the html attribute.