JoshLutrick
JoshLutrick

Reputation: 38

I created a DOM event that isn't giving me the result I wanted

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

Answers (1)

Peterrabbit
Peterrabbit

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

Related Questions