I'm a beginner in web development and currently practicing HTML, CSS, and Javascript. I've added a button to my html file and would like the color of the button to change when it's clicked on.
Here is my HTML code:
<button id="box" style="padding: 20px; background-color: black;"></button>
This is the Javascript I have written:
document.addEventListener('click', event => {
if (event.target.id === 'box') {
document.style.backgroundColor="red";
}
})
I can't figure out why it's not working as expected.