concept bind directive in category svelte

appears as: bind directive
Svelte and Sapper in Action

This is an excerpt from Manning's book Svelte and Sapper in Action.

This works, but it’s a bit verbose. We can do better using the Svelte bind directive. You will see many uses of the bind directive later, but one use is to bind the value of a form element to a variable. This causes the form element to display the current value of the variable. If a user changes the value of the form element, the variable will be updated to match.

  • The class directive toggles the presence of a CSS class based on the truthiness of a variable. See section 3.4.
  • The on directive registers an event listener. See section 5.4.1.
  • The use directive specifies a function that will be passed the DOM element that is created for the element to which this directive is attached. See section 7.2.