May I know how to make the second button work simultaneously with the first button and vise-versa?

Hi,

I hope someone may be able to point me in the right direction or script: https://codepen.io/brodneil/pen/NWyRJqW?editors=1111

It seems the first button works but the scripts only match with the first button. I want to match the functionality to 2 buttons.

Thank you

You could change it so that the buttons have a class reverseImage instead of id reverseImage to make it easier to select both.
And you could use a loop to change the style for each element, one at a time:

function backgroundColor() {
  const collection = document.getElementsByClassName("reverseImage");
  for (let element of collection) {
    element.style.backgroundColor = colors[index];
  }
  index = index >= colors.length - 1 ? 0 : index + 1;
};
1 Like

Excellent. Thank you so much. It woked.