Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To turn off the feature of saving a snapshot of the DOM when using hx-push-url=true in Htmx, you can set the hx-history-elt attribute to an empty string or null value. This will prevent Htmx from saving a snapshot of the DOM in the browser's history when a pushState or replaceState is triggered.

For example, if you have a button that triggers a hx-post request with hx-push-url=true, you can add the hx-history-elt attribute to the button and set its value to an empty string as follows:

<button hx-post="/submit-form" hx-push-url="true" hx-history-elt="">Submit</button>

Alternatively, you can set the hx-history-elt attribute to a selector that targets an element that you don't want to be saved in the history. For example, if you have a form with an ID of "my-form" and you don't want its content to be saved in the history, you can add the hx-history-elt attribute to the form and set its value to "#not-my-form" as follows:

<form id="my-form" hx-post="/submit-form" hx-push-url="true" hx-history-elt="#not-my-form">
  <!-- form content -->
</form>
<div id="not-my-form"></div>