Asked by vinoy · · 1 answer
You can reference DOM elements in Svelte using bind:this
as shown in this example from Svelte's tutorial:
<script>
import { onMount } from 'svelte';
let myInput;
onMount(() => {
myInput.value = 'Hello world!';
});
</script>
<input type="text" bind:this={myInput}/>
Another approach is to use use:action
, as described in the Svelte documentation:
<script>
import { onMount } from 'svelte';
let myInput;
function MyInput(node) {
myInput = node;
myInput.value = 'Hello world!';
}
</script>
<input type="text" use:MyInput/>
0
0