Targets and swaps
Delete a target or skip the main swap
Use delete for a removed element and none when the request has another effect but no normal target representation.
8 minute lesson
Use delete when a successful server operation means the current target no longer has a representation:
<button
hx-delete="/tasks/42"
hx-target="closest li"
hx-swap="delete">
Delete
</button>
After a successful response, HTMX removes the target regardless of the response body. The server must delete the stored task first and return an error when it cannot. Removing DOM optimistically does not authorize or persist anything.
Use none when the normal target should not receive response content:
<button hx-post="/analytics/dismiss" hx-swap="none">
Dismiss tip
</button>
Response headers, events, and out-of-band fragments are still processed with none. That makes it useful for a request whose visible update is elsewhere.
Do not use none to hide a missing success state. If a person needs to know whether an operation worked, return or trigger an accessible confirmation. Force a server error and verify that the target remains recoverable.
Lesson completed