How do I change the background color with JavaScript?

后端 未结 19 2584
春和景丽
春和景丽 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:47

    I would prefer to see the use of a css class here. It avoids having hard to read colors / hex codes in javascript.

    document.body.className = className;
    

提交回复
热议问题