Add a body class when htmx in initialized
Recently I was using htmx to progressively enhance a form. In this use case I was building an interactive form powered by checkboxes. A click on a checkbox posted the form, updating the state of selected items.
I realized that if I know htmx was initialized so that my checkboxes could do their job, I could not display the form submit button for a simpler user experience. This was easily done with a small snippet that set a body class when htmx was defined. That also had the nice extra effect of progressively enhancing the form so that if JS was disabled for some reason so there was no htmx, the submit button was there and the form was still usable.
I am wondering how unique may case is and if we should add a line as htmx initializes to add a class to the body. I used htmx-active as my class.
Source: bigskysoftware/htmx