Part 1 / Events / Event modifiers
DOM event handlers can have modifiers that alter their behaviour. For example, a handler with a once modifier will only run a single time:
App.svelte
<button on:click|once={() => alert('clicked')}>
Click me
</button>The full list of modifiers:
preventDefault— callsevent.preventDefault()before running the handler. Useful for client-side form handling, for example.stopPropagation— callsevent.stopPropagation(), preventing the event reaching the next elementpassive— improves scrolling performance on touch/wheel events (Svelte will add it automatically where it's safe to do so)nonpassive— explicitly setpassive: falsecapture— fires the handler during the capture phase instead of the bubbling phase (MDN docs)once— remove the handler after the first time it runsself— only trigger handler if event.target is the element itselftrusted— only trigger handler ifevent.isTrustedistrue, meaning the event was triggered by a user action rather than because some JavaScript calledelement.dispatchEvent(...)
You can chain modifiers together, e.g. on:click|once|capture={...}.