Does x-teleport.replace (or equivalent) exist? #4223
Replies: 1 comment 6 replies
-
So what is wrong with the appending in that case though? You could also, since you have it, manually do it. document.querySelector('#fragment').replaceWith(domstring) |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I've got a scenario where I've got an Alpine component making a
fetch()
request to get some HTML back from the server. Within my component, I'm usingx-html
to bind the returned HTML content into the UI where I want it. All good.I would however, also like to update another section of my UI with some of the content that comes back in the HTML response. This is a totally separate fragment of my page, so isn't within the scope of the Alpine component that made the initial
fetch()
request. I could extract the DOM nodes from the HTML response and then$dispatch('update-my-fragment', {html: domNodes})
to send the HTML to another Alpine component, but that feels more clunky and labour intensive than I'd ideally like.What ocurred to me was that I'm essentially looking to teleport the HTML to another part of my page. In my head I want to do something like
x-teleport.replace="#fragment"
, however x-teleport appears only to be capable of appending and not replacing.Before I work out how to raise a PR for the functionality I'm looking for, I wondered if others had an existing approach to what I'm describing, and also whether a PR for this is likely to be accepted?
Beta Was this translation helpful? Give feedback.
All reactions