Creating an Action

Let's learn to create Stimulus actions, which link a DOM event to a controller.

Connecting a DOM Event to the Controller

In Stimulus, an action is what connects a DOM event to the controller code that we want to execute when that event occurs. Like controllers, Stimulus actions are defined using a data attribute in the markup; we add the attribute to the DOM element whose events we want to watch. In our case, we want to add a button that says “Hide”:

Get hands-on with 1200+ tech skills courses.