hx-confirm
The hx-confirm attribute allows you to confirm an action before issuing a request. This can be useful
in cases where the action is destructive and you want to ensure that the user really wants to do it.
Here is an example:
<button hx-delete="/account" hx-confirm="Are you sure you wish to delete your account?">
Delete My Account
</button>
Event details
The event triggered by hx-confirm contains additional properties in its detail:
- triggeringEvent: the event that triggered the original request
- issueRequest(): a callback to confirm and issue the AJAX request
- dropRequest(): a callback to cancel the request
- question: the value of the
hx-confirmattribute on the HTML element
Notes
hx-confirmuses the browser’swindow.confirmby default. You can customize this behavior as shown in this example.- If you call
preventDefault()on thehtmx:confirmevent, you must call eitherissueRequest()ordropRequest()— failing to do so will leave the request pending indefinitely.