Understanding $el, $refs, and $root
A server can interact with itself, like running a self-diagnostic and changing its own status light. $el refers to the current DOM element.
<button @click="runSelfCheck($el)">
Run Self-Check
</button>
A central panel can control specific, named systems (like cooling or power). $refs lets you access any element within your component that has an x-ref attribute.
<div x-ref="coolingSystem">...</div>
<button @click="activateSystem()">
...
</button>
// In JS:
this.$refs.coolingSystem.classList.add(...)
Facility Lockdown Active!
All component boundaries are visually marked.
A facility-wide alert or lockdown affects the entire data center boundary. $root refers to the root element of the current Alpine component.
This button will add a red border to this entire card, which is the component's root.
<div x-data="...">
<button @click="$root.classList.add('alert')">
...
</button>
</div>