Skip to content

Add a body class when htmx in initialized #4068

Description

@FatherShawn

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions