Reference Elements by Key: x-ref
Learn to assign keys to DOM elements with x-ref.
We'll cover the following
The x-ref
directive
There are times we want to access some elements on a web page. In pure JavaScript, it’s done with methods in the document
object, such as getElementById
, getElementsByName
and querySelector
. AlpineJS also enables us to achieve the same thing by referencing elements with x-ref
and accessing them with the $refs
magic property:
Get hands-on with 1200+ tech skills courses.