Open the Web page with the background color you wish to change in your preferred text editor.
Insert the following code in the <head> section of your Web page:
document.bgColor = color;
Insert the following code in the tag of the element that you want to trigger the background color change:
Substitute the hexadecimal value of your desired color for #000099.
Save and publish your Web page. Its background will now change to your desired color when the element you specified is clicked with the mouse.
- Photo Credit Stockbyte/Stockbyte/Getty Images