File size: 737 Bytes
7da13d6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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 has `x-data` defined. [β†’ Read more about `x-data`](/directives/data)

[← x-ignore](/directives/ignore)

[x-cloak β†’](/directives/cloak)

Code highlighting provided by [Torchlight](https://torchlight.dev)