Debian Codegraph @

www/src/content/reference/04-config/26-htmx-config-defaultSwapEmpty.md

raw symbols SCIP
1 ---
2 title: "htmx.config.defaultSwapEmpty"
3 description: "Whether an empty response body performs the main swap"
4 ---
5
6 The `htmx.config.defaultSwapEmpty` option sets the default for whether htmx performs the main swap when the server returns an empty response body. It can be overridden per element with the [`swapEmpty`](/reference/attributes/hx-swap#swapempty) modifier on `hx-swap`.
7
8 **Default:** unset. When unset, htmx performs the main swap on an empty response except when the response contained only `<hx-partial>` elements.
9
10 ## Values
11
12 - `true` — perform the main swap on an empty response (clears the target)
13 - `false` — skip the main swap on an empty response (leaves the target unchanged)
14
15 ## Example
16
17 ```javascript
18 htmx.config.defaultSwapEmpty = false;
19 ```
20
21 ```html
22 <meta name="htmx-config" content='{"defaultSwapEmpty":false}'>
23 ```
24
25 Override per element with the [`swapEmpty`](/reference/attributes/hx-swap#swapempty) modifier on `hx-swap`:
26
27 ```html
28 <!-- skip the main swap on an empty response for this element only -->
29 <div hx-swap="innerHTML swapEmpty:false"></div>
30
31 <!-- force the main swap even on an empty response -->
32 <div hx-swap="innerHTML swapEmpty:true"></div>
33 ```