From the course: Hotwire: Reactive Ruby on Rails Applications

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Toggling CSS classes

Toggling CSS classes

- [Instructor] A handy feature of Stimulus is to save CSS classes for using targets. In our case, it could be used to reset the card and leave it blank. Open the template, and in the element where you've defined the controller, define a new attribute, starting with a controller name then the identifier that this class will have. For example, reset. And end it with class. Now in the value, you can write the class you want. At BG white, which is the initial state. Add a new button. I'll copy the existing one. This new button will call a new action named Reset Card, and the content will be reset. Open the controller and define the classes. Specify the name you put in the HTML, reset. Now create the new reset card action. First, delete the inline styles. Then access the list of classes and add the class by its identifier. Reset with the class effects. Let's check it out. Set a color, for example, blue, and now…

Contents