Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hx-indicator via JS API #3217

Open
jacobsorme opened this issue Mar 4, 2025 · 2 comments
Open

hx-indicator via JS API #3217

jacobsorme opened this issue Mar 4, 2025 · 2 comments

Comments

@jacobsorme
Copy link

Is it possible to specify the equivalent of hx-indicator from the JS API ajax()?

https://htmx.org/api/#ajax

@jacobsorme
Copy link
Author

Ended up using this:

document.getElementById("id").classList.add("htmx-request")
htmx.ajax(...).then(() => document.getElementById("id").classList.remove("htmx-request")

Works fine.

@scrhartley
Copy link
Contributor

Otherwise you'd need to specify the source property in the context object you pass, referencing something that exists in the DOM and has hx-indicator on it.
For something slightly shorter than what you have, you can use htmx.addClass and htmx.removeClass:

htmx.addClass("#id", "htmx-request")
htmx.ajax(...).then(() => htmx.removeClass("#id", "htmx-request"))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants