Trouble triggering custom events multiple times #692
-
Hi Folks, I'm trying to get an HTMX element to trigger on a custom event. The problem is that I can trigger it once successfully but not multiple times for some reason. For example, I have the div below that I want to trigger on either a click or when a customEvent is dispatched. <div hx-get="/tickets" hx-target="this" hx-trigger="click, customEvent from: body" hx-swap="afterend"> In Javascript, I create a custom event: const customEvent = new Event('customEvent', { 'bubbles': true }); I load the page in my browser and launch the Inspect Element console. I then trigger this custom event on the body element: body = document.querySelector('body')
body.dispatchEvent(customEvent) The event is dispatched on the body element and HTMX recognizes it and properly gets the HTMX is properly triggering on the I appreciate your help. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
A couple of things.
<div hx-get="/tickets" hx-target="this" hx-trigger="click, customEvent from:body" hx-swap="afterend">
htmx.trigger(htmx.find('body'),'customEvent') |
Beta Was this translation helpful? Give feedback.
A couple of things.
from:
andbody
. I think it's using the space as part of the selector.