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.
1<button
2 hx-confirm="Are you sure you want to delete this post?"
3 hx-delete="/posts/:id"
4>
5 Delete post
6</button>
Note: This works with any request type, not only DELETE
.