How to use response HX-Trigger to trigger the event on a sibling element? #2699
-
I'm trying to send an HX-Trigger and HX-Retarget together to trigger the event in a sibling element. I know I can annotate an element with The only thing that worked was to annotate a parent element. So how can I do it? Is there a way to use |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Hey, hx-on is equivalent to calling And if you really want to stick to hx-on, I imagine a dirty trick could be declaring a hx-on on the parent (that receives the trigger header), that queries all of its children and fires another custom event of yours on them, which would then be listened on by these children using also hx-on but with this other custom event... dirty as I said |
Beta Was this translation helpful? Give feedback.
Hey, hx-on is equivalent to calling
addEventListener
on the element that you put the attribute on, so it cannot be listening "outside" as hx-trigger does. In this case you indeed want to put the listener on the element that will receive the event, be it the body if you need afrom:body
equivalent.When your client logic gets specific enough, it may be worth considering using a simple script of your own and calling addEventListener in it!
And if you really want to stick to hx-on, I imagine a dirty trick could be declaring a hx-on on the parent (that receives the trigger header), that queries all of its children and fires another custom event of yours on them, which would then be listened o…