I have a div which contains several buttons. I would like for only the button that was pressed last to have a different style, to indicate that it was button that has been most recently pressed. Clicking elsewhere on the page or on another page should not affect the buttons in the div.
For example:
There are two styles in CSS for the button: unselected and selected. All buttons have the unselected style when the page loads. If I press button 1, it should change to the selected style. If I then press button 2, button 1 will revert back to the unselected style, and button 2 will change to the selected style.
I’ve tried using the active parameter for the buttons, but the button loses active status if I click on another page.
2
Answers
You can archive this by adding an event listener and maintaining the button lastclicked button.
Maybe something like this? I am assuming you are just using javascript and not React for states. Hope this helps!
html:
<