[JS & CSS] can you trigger the :active CSS of a DOM?

Hello fellow camper. I’m currently working on the react drum machine project and everything is going fine so far, apart from something :

Is it possible to actually trigger the a button via an event listener so that the button’s css becomes :active as if it was clicked on ?

I know it is possible to trigger the function held by the onClick prop of the button using DOM.click() but so far it’s only triggering the function and making the outline of the button visible.

I hope i’m being clear on what i’m asking. Thanks for reading and have a good evening !

Why don’t you create a css class with the properties of how you want the button to look and then add the class when the button is clicked (via a event listener)?

1 Like

It’s what I ended up doing, but since I failed to triger the :active pseudo element, I figured I’d ask since I didn’t know if it was actually possible or not.