1 min read 69 words Updated Oct 03, 2026 Created Oct 03, 2026
#svelte

Also known as the usedirective, and are element-level lifecycle functions.
Svelte Actions are not to be confused with Server actions in SvelteKit


Using an action this way, we can get access to the element in Svelte, as we would be operating in the DOM normally.

  function actionName(node) {
    node.addEventListener('click', () => {
      alert('Hello World')
    })

    node.textContent = 'Hello World'
  } 

// our element: 
<h2 use:actionName>my element</h2>