0

Im making a simon says game, i use 4 colored buttons that works perfectly. the process is simple- the program present the user with the colors. the repeat the sequence by clicking the buttons.

I wish to let the program activate the button the same way a user would, with the appropriate activate effect.

.but:active{ // <-- how do i initiate this with js?
        box-shadow: 0 5px #666;
        transform: translateY(4px);

2 Answers2

2

You mean

document.querySelector(".but").click()

or

const buts = document.querySelectorAll(".but");
const cnt = 0;
setInterval(function() { 
  if (cnt>= 0) cnt = 0; 
  but[cnt].click();
  cnt++;
},2000)
mplungjan
  • 169,008
  • 28
  • 173
  • 236
0
let but = document.querySelector('.but');

but.addEventListener('click', () => {
   but.classList.add('active');

   let activeStatus = document.querySelector('.active');
   activeStatus.style = `
   box-shadow: 0 5px #666;
   transform: translateY(4px);
  `;
});
Adrian Mole
  • 49,934
  • 160
  • 51
  • 83