m-
m- copied to clipboard
The connectedCallback runs multiple times
Like the subject says, when you move/drag drop elements in the DOM, the connectedCallback
will run again.
I'd need more info @Danny-Engelman. Is this in regards to a specific component or all of the Custom Element components?
The connectedCallback
runs for every (re)placement in the DOM
https://jsfiddle.net/WebComponents/mc1o94kw/
<script>
customElements.define('my-element', class extends HTMLElement {
connectedCallback() {
this.innerHTML += "<h1>Click me!</h1>";
this.onclick = (evt) => document.body.append(this);
}
});
</script>
<my-element></my-element>