Change the background color of the current document:
document.body.style.backgroundColor = "yellow";
Click the button to change the background color of the document.
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <script> function myFunction() {/*from w w w. j a va2s .c om*/ document.body.style.backgroundColor = "yellow"; } </script> </body> </html>
The body property sets or gets the document's body.
The body property returns the <body> element of the current document.
The document.body element returns the <body> element.
The document.documentElement returns the <html> element.