-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Add FAQ or explanaition on how HX-Trigger events bubble #187
Comments
The If you want to catch the event you need to be in the parent hierarchy of the receiving element: <div hx-trigger="myEvent" hx-target="otherDiv" hx-get="/waiting">
<button hx-post="/event">
Click Me
</button>
</div>
<div id="otherDiv">
Waiting for myEvent.
</div>
<script>
document.body.addEventListener("myEvent", function(evt){
alert("myEvent was triggered!");
})
</script> Here we've moved all the htmx attributes to a parent div. (I also eliminated the Hope that clarifies. |
This seems like it's a FAQ like item; or part of a usage guide. There's no way that I'd know this nugget of information; the failed and the working example are very helpful. |
Reopened for a doc update |
Hello everyone!
First off, I want to say that I really appreciate your work and found the htmx API very attractive.
Now we can move to my little issue. Let's consider following code.
HX-Trigger
header of/event
endpoint is set tomyEvent
. Can someone explain me why alert is firing but div withhx-trigger
set tomyEvent
isn't?The text was updated successfully, but these errors were encountered: