How do I change the background color with JavaScript?

后端 未结 19 2335
春和景丽
春和景丽 2020-11-22 13:59

Anyone know a simple method to swap the background color of a webpage using JavaScript?

19条回答
  •  花落未央
    2020-11-22 14:40

    if you wish to use a button or some other event, just use this in JS:

    document.querySelector("button").addEventListener("click", function() {
    document.body.style.backgroundColor = "red";
    });
    

提交回复
热议问题