Hacker News new | ask | show | jobs
by 411111111111111 1066 days ago
hx-on is the general js API from htmx, it's essentially a wrapper/shortcut for creating a js event handler. The htmx docs provide some examples

https://htmx.org/attributes/hx-on/

1 comments

I had found that. It has the "what" but not the "where or why"
You mean htmx in general?

The author of htmx wrote a rationale (when and when not to use it). https://htmx.org/essays/when-to-use-hypermedia/

Good article, but I saw no mention of hx-on
Because HTML's on* attributes are not generic, they are hardcoded in the spec, you can't use them to handle arbitrary events. hx-on is an attempt to fill this gap for simple cases, when managing event listeners manually or resorting to _hyperscript or alpine is too much

> it addresses a specific shortcoming of HTML: the on* attributes do not support arbitrary events

> it is much less featureful & useful than, for example, @Alpine_JS, but if you have very basic needs for event handling it can help avoid another dependency

https://nitter.net/htmx_org/status/1679966199667478531#m

> it addresses a specific shortcoming of HTML: the on* attributes do not support arbitrary events

Yes, I saw that. But what does it have to do with XPath?

XPath is implementation detail, used for searching of attributes with a give prefix, and this article is just a public note of how it was done in htmx
Got it. Thanks.