Reputation: 38
I created a function to change the color value of my elements. I used the same function on both elements with different events but my second element isn't changing only the first element.
function colorChange(event){
let randomColor = 'rgb(' + colorValue() + ',' + colorValue() + ',' + colorValue() + ')';
button.style.backgroundColor = randomColor
}
button.addEventListener('click', colorChange);
mysteryButton.onwheel = colorChange;
Upvotes: 1
Views: 38
Reputation: 2247
Maybe you should try instead
function colorChange(event){
let randomColor = 'rgb(' + colorValue() + ',' + colorValue() + ',' + colorValue() + ')';
event.target.style.backgroundColor = randomColor
}
button.addEventListener('click', colorChange);
mysteryButton.onwheel = colorChange;
Upvotes: 1