Using a Web Browser analogy.
An element referencing itself. Like a browser tab that knows its own content and can change its own title.
Click the "tab" to change its state.
<button @click="setActiveTab($el)">
...
</button>
Accessing other specific elements from one place. Like a bookmark bar that can activate any bookmarked site.
<button @click="focusBookmark('siteA')">
...
<div x-ref="siteA">...</div>
// In JS
this.$refs.siteA.classList.add(...)
Accessing the component's top-level element. Like a setting that changes the theme of the entire browser window.
This button will affect the entire demo area.
The component root is outlined in green for clarity.
<div x-data="myComponent">
<button @click="toggleTheme()">
</div>
// In JS
toggleTheme() {
this.$root.classList.toggle('dark');
}