diff options
author | Adam Johnson <me@adamj.eu> | 2022-02-04 17:51:05 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-04 10:51:05 -0700 |
commit | 4b572b8e3d438e7f8f43ed412c076b9d94061006 (patch) | |
tree | c66080d5d4f05d89b31bfc334a5593745c82a1fd | |
parent | f1cef92e528871993df1a5569b30bb94c99ec847 (diff) | |
download | htmx-4b572b8e3d438e7f8f43ed412c076b9d94061006.tar.gz htmx-4b572b8e3d438e7f8f43ed412c076b9d94061006.zip |
Clarify hx-preserve docs (#798)
I mistakenly thought that I could mark a (third party) node with `hx-preserve` and it would be carried onto the next page, but this is not the case. This makes sense. I’ve tried to improve the documentation to reflect this, and make the behaviour clearer in general.
-rw-r--r-- | www/attributes/hx-preserve.md | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/www/attributes/hx-preserve.md b/www/attributes/hx-preserve.md index 7107ef07..5017288b 100644 --- a/www/attributes/hx-preserve.md +++ b/www/attributes/hx-preserve.md @@ -5,8 +5,10 @@ title: </> htmx - hx-preserve ## `hx-preserve` -The `hx-preserve` attribute allows you to keep a section of content unchanged between HTML replacement. When hx-preserve is set to `true`, an element is preserved (by id) even if the surrounding HTML is updated by htmx. An element *must* have an `id` to be preserved -properly. +The `hx-preserve` attribute allows you to keep an element unchanged during HTML replacement. +Elements with `hx-preserve` set are preserved by `id` when htmx updates any ancestor element. +You *must* set an unchanging `id` on elements for `hx-preserve` to work. +The response requires an element with the same `id`, but its type and other attributes are ignored. Here is an example of a youtube embed, which would be unaffected an htmx request: |