Home Writing

til / htmx: confirm an action

When using hx-delete, which sends a DELETE request, it’s a good idea to have the user confirm the action to avoid losing data accidentally. This can be achieved by adding one htmx attribute, hx-confirm, which displays the browser’s native confirmation modal before running an action.

  hx-confirm="Are you sure you want to delete this post?"
  Delete post

Note: This works with any request type, not only DELETE.

  • Loading next post...
  • Loading previous post...