how to make a background-color on a div tag

后端 未结 2 1120
礼貌的吻别
礼貌的吻别 2021-01-29 06:54

I have this code:

 
2条回答
  •  后悔当初
    2021-01-29 07:15

    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.

提交回复
热议问题