Edit This Code:
See Result »
<!DOCTYPE html> <html> <body> <h3>A demonstration of how to access a BODY element</h3> <p>Click the button to set the background color of the document to red.</p> <button onclick="myFunction()">Try it</button> <p id="demo"></p> <script> function myFunction() { var x = document.getElementsByTagName("BODY")[0]; x.style.backgroundColor = "red"; } </script> </body> </html>
Result: