help understanding HTMX behavior and JS #1158
-
I have a simple web app (written in Go) that combines HTMX and TailwindCSS/Flowbite. I tried to use a simple dismissible alert component from Flowbite. When I display the alert on the initial page load, the dismiss button works fine, but when I include the alert within an HTML fragment returned from I can workaround this problem with a little bit of hyperscript, It seems like the Flowbite Javascript responsible for removing the alert is never run on the new HTML fragment that HTMX replaces in the DOM. But I'm not sure how I'd confirm that? One oddity, which may be unrelated, is that even though the page displays the new HTML fragment returned from the server, Chrome Dev Tools always shows the original I scoured the HTMX docs and wonder if this is somehow related to 3rd party JS but I can't figure out the relationship or how to address it (without hyperscript) if so. I'd like to understand this behavior better so I can anticipate when JS may not apply to HTML fragment updates. Thx in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
Hi @bfallik , It all depends on how JS events listeners are bound to DOM elements. Flowbite source code for What you can do is plug a call to that function from the |
Beta Was this translation helpful? Give feedback.
-
Just in case anyone else stumbles on this discussion, after understanding the response from @David-Guillot , I was able to get things working with the following code included in the fragment:
|
Beta Was this translation helpful? Give feedback.
Hi @bfallik ,
It all depends on how JS events listeners are bound to DOM elements.
Flowbite source code for
dismiss
component contains an initDismiss() function that is bound to DOMContentLoaded event. So it doesn't get called when htmx loads an HTML fragment.What you can do is plug a call to that function from the
htmx:load
event.