Skip to content

Commit 0c6f20e

Browse files
manwithacatclaude
andcommitted
docs: clarify HX-Retarget interaction with hx-swap="none" (#3446)
HX-Retarget only changes *where* the swap happens — the swap style is still determined by the source element's hx-swap (or by HX-Reswap). When the source uses hx-swap="none", retargeting alone produces a no-op because the "none" swap style applies at the new target too. Updates the HX-Retarget entries in both docs.md and reference.md to spell this out and point users at HX-Reswap. The behavior itself is intentional and consistent — only the docs were silent on this combination. The original issue reporter noticed the surprise and explicitly suggested "I would update the docs to include that setting hx-swap='none' will prevent the use of a swap via HX-Retarget." Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent dbf77dd commit 0c6f20e

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

www/content/docs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,7 @@ htmx supports some htmx-specific response headers:
10381038
* `HX-Refresh` - if set to "true" the client-side will do a full refresh of the page
10391039
* [`HX-Replace-Url`](@/headers/hx-replace-url.md) - replaces the current URL in the location bar
10401040
* `HX-Reswap` - allows you to specify how the response will be swapped. See [hx-swap](@/attributes/hx-swap.md) for possible values
1041-
* `HX-Retarget` - a CSS selector that updates the target of the content update to a different element on the page
1041+
* `HX-Retarget` - a CSS selector that updates the target of the content update to a different element on the page. Note that this only changes *where* the swap happens; the swap style is still determined by the source element's [`hx-swap`](@/attributes/hx-swap.md) (or `HX-Reswap`). If the source uses `hx-swap="none"`, you also need to send `HX-Reswap` to make the swap actually occur at the new target.
10421042
* `HX-Reselect` - a CSS selector that allows you to choose which part of the response is used to be swapped in. Overrides an existing [`hx-select`](@/attributes/hx-select.md) on the triggering element
10431043
* [`HX-Trigger`](@/headers/hx-trigger.md) - allows you to trigger client-side events
10441044
* [`HX-Trigger-After-Settle`](@/headers/hx-trigger.md) - allows you to trigger client-side events after the settle step

www/content/reference.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ All other attributes available in htmx.
116116
| `HX-Refresh` | if set to "true" the client-side will do a full refresh of the page
117117
| [`HX-Replace-Url`](@/headers/hx-replace-url.md) | replaces the current URL in the location bar
118118
| `HX-Reswap` | allows you to specify how the response will be swapped. See [hx-swap](@/attributes/hx-swap.md) for possible values
119-
| `HX-Retarget` | a CSS selector that updates the target of the content update to a different element on the page
119+
| `HX-Retarget` | a CSS selector that updates the target of the content update to a different element on the page (only changes *where* the swap happens; combine with `HX-Reswap` if the source has `hx-swap="none"`)
120120
| `HX-Reselect` | a CSS selector that allows you to choose which part of the response is used to be swapped in. Overrides an existing [`hx-select`](@/attributes/hx-select.md) on the triggering element
121121
| [`HX-Trigger`](@/headers/hx-trigger.md) | allows you to trigger client-side events
122122
| [`HX-Trigger-After-Settle`](@/headers/hx-trigger.md) | allows you to trigger client-side events after the settle step

0 commit comments

Comments
 (0)