Understanding $el, $refs, and $root with a simple analogy.
No activity yet...
$el refers to the current DOM element. It's like the specific tool you're holding. You can command it to change itself directly.
Interactive Demo:
Code Example:
$refs lets you access other elements by a name you give them with x-ref. It's like having labeled workbenches you can refer to from anywhere in the workshop.
Interactive Demo:
Code Example:
$root refers to the root element of the Alpine component. It's the entire workshop space. You can trigger a workshop-wide change from any button inside it.
Interactive Demo:
Notice the border and background of the entire "My Workshop" area change.
Code Example: