Spaces:
Running
Running
x-ref
x-ref
in combination with $refs
is a useful utility for easily accessing DOM elements directly. It's most useful as a replacement for APIs like getElementById
and querySelector
.
<button @click="$refs.text.remove()">Remove Text</button> <span x-ref="text">Hello π</span>
<button @click="$refs.text.remove()">Remove Text</button>
<span x-ref="text">Hello π</span>
Remove Text
Hello π
Despite not being included in the above snippet,
x-ref
cannot be used if no parent element hasx-data
defined. β Read more aboutx-data
Code highlighting provided by Torchlight