Complete the code to bind the input value to the variable.
<script> let name = ''; </script> <input type="text" [1]={name}> <p>Hello, {name}!</p>
In Svelte, bind:value binds the input's value to the variable, keeping them in sync.
Complete the code to bind the checkbox checked state to the variable.
<script> let accepted = false; </script> <label> <input type="checkbox" [1]={accepted}> Accept terms </label>
Checkboxes use bind:checked to bind their checked state to a variable in Svelte.
Fix the error in binding a select element's value to the variable.
<script> let color = 'red'; </script> <select [1]={color}> <option value="red">Red</option> <option value="green">Green</option> <option value="blue">Blue</option> </select>
For select elements, bind:value binds the selected option's value to the variable.
Fill both blanks to bind a custom component's prop and listen to its event.
<script> import Child from './Child.svelte'; let count = 0; </script> <Child [1]={count} on:[2]={() => count++} />
To bind a prop named count in a child component, use bind:count. To listen for a click event, use on:click.
Fill all three blanks to bind a textarea value, handle input event, and update a variable.
<script> let message = ''; function handleInput(event) { [1] = event.target.[2]; } </script> <textarea [3]={message} on:input={handleInput}></textarea> <p>Message length: {message.length}</p>
The variable message is updated with the textarea's value. The textarea binds its value with bind:value.