DEV Community

Discussion on: How to make a button looked like it's staying pressed down

nicm42 profile image
Nic Author

setTimeout is your friend here. You can add it into the click listener after you set the button to look pressed:

  setTimeout(() => { button.classList.remove('active'); }, 2000);
Enter fullscreen mode Exit fullscreen mode

The 2000 there is the number of milliseconds it should wait before it executes. 2000ms is 2 seconds.

You can see the whole thing in the Codepen at

fiddeou profile image
Esteban Fiddeou

Cool thanks!