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


I hope someone may be able to point me in the right direction or script:

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) { = colors[index];
  index = index >= colors.length - 1 ? 0 : index + 1;
1 Like

Excellent. Thank you so much. It woked.