htmx
htmx copied to clipboard
hx-trigger="click from:.class" are not updated
Given a div like:
<div id="container" hx-get="/target" hx-trigger="click from:.literal" class="thebox">
...
</div>
This works fine (finding all things which match .literal
), but if I load a new thing via htmx, it is not scanned. Further, even if I run htmx.process(document.documentElement)
, to (I believe) force a full scan, the things with class literal
still aren't found, I think because htmx notices the div
hasn't changed, so it doesn't rescan it.
If I "poke" the div, by giving it a new class (for example), then run htmx.process(document.documentElement)
, then it will finally find new items with the .literal
class.
While my actual problem is a htmx problem, I load a div, which contains an svg, where lots of items have the ".literal" class, and they don't become clickable.
I've tried to write a minimal awful HTML+Javascript example to show the problem (attached)
It has 3 buttons:
The first adds the class 'literal' to the text 'hello world', but it doesn't become clickable.
The second runs 'htmx.process', but that doesn't fix it
The third changes the div with the 'hx-get', attaching a new 'class' to it. This still doesn't fix it.
However, now reclicking on the second button now correctly rescans, and we can finally click on 'hello world', and get a result.
I feel like there are two(ish) issues here (but I might be misunderstanding my problem)
-
When HTMX loads something, it should maybe try reapplying any triggers with a 'from', to see if they apply to the new content.
-
htmx.process shouldn't try to cleverly skip things with a 'hx-trigger' with 'from' (if that's what it's doing).