htmx/www/content/attributes/hx-post.md
William Jackson 46badfe0b1
Add descriptions for attribute pages (#3158)
Descriptions for attribute pages
2025-02-07 17:07:13 -07:00

1.0 KiB

+++ title = "hx-post" description = """
The hx-post attribute in htmx will cause an element to issue a POST request to the specified URL and swap the
returned HTML into the DOM using a swap strategy.""" +++

The hx-post attribute will cause an element to issue a POST to the specified URL and swap the HTML into the DOM using a swap strategy:

<button hx-post="/account/enable" hx-target="body">
  Enable Your Account
</button>

This example will cause the button to issue a POST to /account/enable and swap the returned HTML into the innerHTML of the body.

Notes

  • hx-post is not inherited
  • You can control the target of the swap using the hx-target attribute
  • You can control the swap strategy by using the hx-swap attribute
  • You can control what event triggers the request with the hx-trigger attribute
  • You can control the data submitted with the request in various ways, documented here: Parameters