How does htmx reapply event listeners to HTML coming from the server via AJAX requests? #3431
Replies: 1 comment
|
Ran into this exact question before, so I checked how htmx actually re-attaches things on swap. Short version: it doesn't reapply your You're already doing the correct thing by hooking
Delegation is the one I'd reach for here since you said "efficient way" — one listener on the container instead of rebinding N buttons after every swap. |
Uh oh!
There was an error while loading. Please reload this page.
For example: let's say that I make an AJAX request that replaces an entire
and that table itself has buttons that I have addEventListener on. How can I repply those after htmx has replaced the content, in an efficient way? I'm basically having to reapply manually onhtmx:afterSwap.All reactions