Home Writing Reading

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.

<button
  hx-confirm="Are you sure you want to delete this post?"
  hx-delete="/posts/:id"
>
  Delete post
</button>

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


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