htmx icon indicating copy to clipboard operation
htmx copied to clipboard

HX-Reselect does not support "unset" (like hx-select does)

Open oliverhaas opened this issue 1 year ago • 2 comments

Pretty much the title.

HX-Reselect does not support unset like hx-select does.

I guess this is a pretty rare case, but I wanted to basically do the following:

<button hx-select="#some_div" hx-target="#some_div">
  Click me
</button>

Then on the server side I want to switch to a body swap, and since hx-select is set I need to unset it.

HX-Retarget = "body"
HX-Reselect = "unset"

Such a body swap might be the only case where unset really matters, since otherwise one is probably able to just work with css selectors. In this case I don't think there is a way. Yes, I've tried :scope, :host, *, > *, and all other suggestions for the selector I could find. maybe I'm missing something...

But in any case: I think it would be nice if htmx would just support the HX-Reselect override with unset like one would expect.

oliverhaas avatar Jan 28 '25 11:01 oliverhaas

For current version, does HX-Reselect = "*" work as same as unset?

mic4126 avatar May 08 '25 08:05 mic4126

I think the problem with work-arounds such as HX-Reselect = ":scope > *" is that they will only match elements and not immediate text nodes. That limitation will be fine in some cases and not others.

scrhartley avatar May 14 '25 15:05 scrhartley