-
How to target parent without any assumptions about it? It seems like an essential feature for building self-contained widgets that don't rely on any particular surrounding HTML structure. Now I ended up wrapping them in a root element, whose purpose is only to be a target for `hx-target="closest [data-widget-root]". |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
If you don't want to rely on the wrapping structure or the widget's surroundings in general, you will probably not want to target any of those other elements anyway. |
Beta Was this translation helpful? Give feedback.
This sounds convoluted to me for a "self-contained widget" as you then directly depend on the parent element's styling, for ex a flex row vs a standard block display, could mess up your widget's display.
I would suggest using a root element to enclose your self contained widget as you described in your initial post in this case.
As far as I know, there's no current straightforward selector to achieve exactly what you want (
closest *
will target the element itself as that's howElement.closest
works, by checking the element itself first)A convoluted way could be using
closest :not(#id)
(in your example above, for ex<input hx-tar…