I am facing an issue with a button on my HTML page. When the button is clicked, I want its background color to change to a random different color. However, despite trying various sources, I am unable to get it right. It seems like I am not placing the code correctly.
**JS:**
var randomColor = Math.floor(Math.random()*16777215).toString(16);
document.getElementsById("mainButton").style.background = randomColor;
**HTML:**
<button id="mainButton">click</button>
**CSS:**
#mainButton{
background-color: white;
font-family: monospace;
border: none;
width: 100%;
height: 100%;
position: absolute;
right: 0;
top: 0;
}
I would appreciate any guidance or tips that could help me solve this issue. Thank you!