Svelte · Junior · Question 24 of 76
How do you get a reference to a DOM element?
<script>
let canvas;
</script>
<canvas bind:this={canvas}></canvas>- ✓Correct answer: With
bind:this; the variable is set after the element is mounted - 2With
ref={canvas} - 3With
document.querySelectorinside the markup
Explanation
The value is undefined until mount, so use it in $effect, onMount or event handlers.