javascript / beginner
Snippet
Event Modifiers
Svelte allows you to add modifiers to events using the pipe symbol. |preventDefault stops the browser's default behavior, like reloading the page on form submission.
snippet.js
1
2
3
<form on:submit|preventDefault={() => console.log('Form sent!')}><button type="submit">Send</button></form>
svelte
Breakdown
1
on:submit|preventDefault
Listens for the submit event and calls preventDefault() automatically before running the handler.
2
() => console.log(...)
The inline function that executes when the button is clicked and the form attempts to submit.