Question · Svelte and SvelteKit course · Module 1: Introduction to Svelte

Preventing the Default Action

How do you prevent the browser's default action in Svelte 5, e.g. a page reload after a form is submitted?

Answer options

  • Call event.stopPropagation() in the handler function
  • Call event.preventDefault() in the handler function
  • Add |preventDefault to the onsubmit attribute
  • Add capture at the end of the event name
Show the answer

Correct answer:

  • Call event.preventDefault() in the handler function