Javascripts > Javascript Windows > Change Background Color
Script Title: Change Background Color
Description: When the button is clicked, it changes the background color of the page randomly.
Example: No example available for this script.
Copy the following code into your <HEAD></HEAD> tags.<script> function changeBackgroundColor() { const colors = ['#FF5733', '#33FF57', '#5733FF', '#FF33D1', '#33D1FF', '#D1FF33']; const randomColor = colors[Math.floor(Math.random() * colors.length)]; document.body.style.backgroundColor = randomColor; } </script>
Copy the following code between the <BODY></BODY> tags of your html page.<button onclick="changeBackgroundColor()">Click Me To Change Background Color</button>
Enter your name and email address to have this script sent right to your Inbox for later viewing. First Name Last Name Email