-
A list of items with a "load more" button; the response will contain more items and a new button: <div>Item 1</div>
<div>Item 2</div>
<div>Item 3</div>
<!-- ... -->
<div id="more">
<button hx-get="/load-items?page=2"
hx-on:htmx:after-swap="alert('swapped!')"
hx-target="#more"
hx-swap="outerHTML"
>Load next page<button>
</div> The Is there some setting to make this work, or must I redesign the markup? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hey, Just as you suspected,
Htmx indeed cleans up elements when replacing them (i.e. removes any htmx listener and internal data) Lines 1720 to 1722 in 90a91a6
Feel free to give us more detail on what you're trying to achieve if you need more guidance on the implementation Hope this helps! |
Beta Was this translation helpful? Give feedback.
Hey,
Just as you suspected,
Htmx indeed cleans up elements when replacing them (i.e. removes any htmx listener and internal data)
htmx/src/htmx.js
Lines 1720 to 1722 in 90a91a6
htmx:beforeCleanupElement
event that htmx fires right before unitializing an element (if you need to run some logic when it gets replaced, you could do it here)