Accessing the root element in Stimulus
This blog post was originally published a little while ago. Please consider that it may no longer be relevant or even accurate.
Sometimes you might want to access the root element of your controller when using Stimulus - the element you have the data-controller
attribute attached to. You could hook up a target to get access to it, but there's an easier way - it's simply available on your controller as this.element
.
A blog about Laravel & Rails by Dwight Watson;
- building Roomies, myInspections & High School Notes.
- previously myRent & Flatmates.
