HTMX: Passing a function to `hx-on` for reading the event
05:55 10 Nov 2023

I must be missing the absolute obvious here:

Using htmx I am trying to send a get request and configure it in javascript before sending it. HTMX provides hx-get, hx-on and the configRequest event for basically exactly that.

However I seem to be missing a big obvious button since I could not get hx-on to perform a function or lambda I give it, only immediate JS works which (by it's nature) cannot accept arguments and therefor cannot access the event.

In short: What am I missing to get the following to work as expected?


...

  • hx-on:config-request="console.log('This will work πŸ‘')" will work but obviously cannot engage with the event.
  • hx-on:config-request="() => console.log('This won't work πŸ‘Ž')" won't work
  • hx-on:config-request="console.log" won't work as well
  • hx-on:config-request="someOtherKnownMethod" won't work as well

I'm confused. πŸ˜•

Thanks for your time. Some ideas?

javascript html event-handling htmx