Set a background color for a document:
document.body.style.backgroundColor = "red";
<!DOCTYPE html> <html> <body> <h1>Hello World!</h1> <button type="button" onclick="myFunction()">Set background color</button> <script> function myFunction() {//w w w .j a v a 2 s. c om document.body.style.backgroundColor = "red"; } </script> </body> </html>