This content originally appeared on CodeSource.io and was authored by Jatin Hemnani
In this article, you will learn How To Bind Checkbox In Svelte.
Checkboxes are used for toggling between states and to show some data depending on the checkbox.
Binding Checkbox
<script>
let visible=true
</script>
<input type=checkbox bind:checked={visible} />Check
{#if visible}
<h1>Visible</h1>
{:else}
<h1>Not Visible</h1>
{/if}
Here we have a variable with a Boolean value and we’ll show data on the basis of the checkbox. You just have to add bind:checked for checkboxes and Svelte will toggle it accordingly.
You can use the toggle variable and show some data using {#if} block in Svelte.
Result
The post Bind Checkbox In Svelte – Code Example appeared first on CodeSource.io.
This content originally appeared on CodeSource.io and was authored by Jatin Hemnani
Jatin Hemnani | Sciencx (2021-02-19T15:07:11+00:00) Bind Checkbox In Svelte – Code Example. Retrieved from https://www.scien.cx/2021/02/19/bind-checkbox-in-svelte-code-example/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.