You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: www/content/attributes/hx-preserve.md
+12Lines changed: 12 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,6 +10,18 @@ The response requires an element with the same `id`, but its type and other attr
10
10
Note that some elements cannot unfortunately be preserved properly, such as `<input type="text">` (focus and caret position are lost), iframes or certain types of videos. To tackle some of these cases we recommend the [morphdom extension](https://github.com/bigskysoftware/htmx-extensions/blob/main/src/morphdom-swap/README.md), which does a more elaborate DOM
11
11
reconciliation.
12
12
13
+
## OOB Swap Usage
14
+
15
+
You can include `hx-preserve` in the inner response of a [hx-swap-oob](@/attributes/hx-swap-oob.md) and it will preserve the element unchanged during the out of band partial replacement as well. However, you cannot place `hx-preserve` on the same element as the `hx-swap-oob` is placed. For example, here is an oob response that replaces notify but leaves the retain div unchanged.
16
+
17
+
```html
18
+
<divid="notify"hx-swap-oob="true">
19
+
<p>The below content will not be changed</p>
20
+
<divid="retain"hx-preserve>Use the on-page contents</div>
21
+
</div>
22
+
```
23
+
13
24
## Notes
14
25
15
26
*`hx-preserve` is not inherited
27
+
*`hx-preserve` can cause elements to be relocated to a new location when swapping in a partial response
0 commit comments