htmx:before:cleanup
Fires before element data removal
The htmx:before:cleanup event fires before htmx removes listeners and internal data from an element.
When It Fires
- Before an element is removed from the DOM during a swap
- Before htmx re-processes an element
Event Detail
Empty - no additional context provided.
Example
htmx.on('htmx:before:cleanup', (evt) => {
console.log('Cleaning up:', evt.target);
// Save state or clean up custom data
}); Use this to perform cleanup operations before htmx removes its data.
Licensed under the Zero-Clause BSD License.
https://four.htmx.org/reference/events/htmx-before-cleanup/