Search code examples
javascripthtmldomsveltesvelte-component

svelte create and pass component as html element


I'm using a library which requires me to create an html element and pass that element. Then the library puts the element in the correct place internally.

The problem I'm facing is that the element i create using document.createElement is not styled and adding all the styles using js feels backwards..

Is it somehow possible to have the element i want to create be a svelte component with it's own style? So that it can be passed to the library which requires an html-element?


Solution

  • You can create a container element (e.g. a div) and mount a component on it using the client-side API (set target to said element).