There are 2 parts to the problem i am facing
- I am trying to mount a component on two divs with same class name but the svelte component is loaded on the first target element.
- When i append an element on a click of a button , Svelte component targetting it must be loaded.
I am trying to achieve these cause i am working on a SPA application where widgets are added on click of a button.
My index.html looks like
<script>
function addTable() {
var iDiv = document.createElement('div');
iDiv.className = 'table';
document.body.appendChild(iDiv);
}
</script>
<body>
<div class="table"></div>
<div class="table"></div>
<button onclick="addTable()">Add Table</button>
<script src='bundle.js'></script>
</body>
And my main.js looks like
import App from './App.svelte';
const app = new App({
target: document.querySelector('.table')
});
export default app;