Understanding $el, $refs, and $root through music.
A musician refers to themselves. When asked to "play a solo," the musician who was addressed is the one who performs. $el is a magic property that gives an element direct access to itself.
<div class="musician" @click="takeSolo($el)">Violin</div>
<div class="musician" @click="takeSolo($el)">Cello</div>
The conductor doesn't point at every instrument individually. They call them by name: "Violins, your part now!". $refs lets you access elements within your component that you have given a specific name using x-ref.
<!-- Conductor's Podium -->
<button @click="cue('strings')">Cue Strings</button>
<!-- Orchestra Pit -->
<div x-ref="strings">...</div>
<div x-ref="brass">...</div>
Sometimes an action affects the entire performance space, like changing the stage lighting. $root refers to the top-most element of the current Alpine component, allowing you to manipulate the entire component boundary from within.
<div x-data="rootDemo"> <!-- This is $root -->
<div>Musicians...</div>
<button @click="toggleSpotlight()">
Toggle Spotlight
</button>
</div>
This button is inside the component, but it will affect the entire component's container.
The Musician Themselves
The element the event listener is on.
A Named Instrument Section
A specifically named element (x-ref) within the component.
The Entire Orchestra Stage
The top-level element of the component (x-data).