Hi, I'm learning JavaScript and I have a problem with the following exercise
within my html
I have my ID
which have the name red and blue colors.
and within my JS I have my next line of code.
const redButton = document.getElementById('redButton');
const blueButton = document.getElementById('blueButton');
redButton.addEventListener('click', (e) => {
const colorSquare = document.getElementById('colorDiv');
colorSquare.style.backgroundColor = 'red';
});
blueButton.addEventListener('click', (e) => {
colorSquare.style.backgroundColor = 'blue';
})
What I want is that when you click click on the network button, the ID
colorDiv
change color to red and when you do click on the blue button change the color to blue.
I think that the way to do this is with conditional if
and else
, but I do not know how to declare it for this event to take place.