0Pricing
Sveltejs Academy · Lesson

use: Directive Syntax

Apply a Svelte action to a DOM element using the use: directive.

Actions in Svelte

An action is a function that runs when an element is mounted. It is invoked with the use: directive.

Basic Action

An action receives the DOM node as its argument.

function highlight(node) {
  node.style.background = "yellow";
}

All lessons in this course

  1. use: Directive Syntax
  2. Action Parameters and Updates
  3. The destroy() Cleanup Function
  4. Practical Actions: clickOutside tooltip autofocus
← Back to Sveltejs Academy