Understanding `$root`, `$el`, and `$refs`
These buttons control the entire component boundary (the dashed border). `$root` refers to this entire container.
Click on a student. The action uses `$el` to target the specific student element that was clicked, without needing to know which one it was in advance.
These buttons target specific, named areas within the classroom using `$refs`. Notice how the action is triggered from one place but affects another.
> Waiting for activity...
Refers to the root element of the Alpine component, in this case <div x-data="classroom">. It's useful for broad actions that affect the entire component, like changing its overall appearance.
this.$root.classList.add('classroom-active');
Refers to the specific DOM element the directive is on. In our demo, when you click a "student", $el is that specific student's div. It allows an element to act on itself.
<div @click="studentAction($el, 'Alex')">...</div>
Allows you to access other specifically named elements from anywhere within the component. You "name" an element with x-ref="name" and then access it via this.$refs.name.
this.$refs.readingCorner.classList.add('area-active');