hx-swap-oob requires target having an ID
See original GitHub issueI have potentially multiple avatar in a page so the avatar is defined as
<div class="avatar">
</div>
without an id.
After the avatar is updated from a hx-post="update_profile" somewhere, the returned piece has
<div class="avatar" hx-swap-oob="true:.avatar">
</div>
which, according to the doc on hx-swap-oob, would update the first avatar, which would be the one on the header and I am ok with it. However, the code triggers
DOMException: Failed to execute 'querySelector' on 'Document': '#' is not a valid selector.
from what I believe by line 453 of this piece of code
despite the fact that the oobElement is found by class name so no id is required.
The code also appears to suggest that all matching elements will be replaced (which is even better for me), instead of “If a selector is given, the first element matching that selector will be swapped.”.
Is this a bug?
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (5 by maintainers)
Top Results From Across the Web
hx-swap-oob - </> htmx
The hx-swap-oob attribute allows you to specify that some content in a response should be swapped into the DOM somewhere other than the...
Read more >Can hx-select-oob update several targets? - Stack Overflow
If your goal is to return html content and copy the same content to multiple targets - you simply use class selector instead...
Read more >Out-of-band swaps with HTMX - .NET Guide - JetBrains
So, we have a cart button with an id of cartNavbar in our example. HTMX can process responses before placing them into our...
Read more >Thymeleaf and htmx with out of band swaps - Wim Deblauwe
After that, it will use any additional HTML marked with hx-swap-oob="true" and swap that with the HTML already on the page, given the...
Read more >HTMX and ASP.NET Core Swapping Techniques
Next, let's look at the fragment returned by ASP.NET Core. <div id="red" hx-swap-oob="true"> ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Best to create a new issue for this, this issue has become stale and too long.
My PR was wrong but the feature request was valid.