I'm trying to make somewhat of a reusable header for a website (multiple pages, can't be bothered to copy/paste everything); inside it I only have a logo-element
element (custom as well) whose id I want to make equal to the header's plus a __logo
suffix.
Here's the javascript:
class TopBar extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: "open" });
let logoElement = document.createElement("logo-element");
logoElement.setAttribute("id", `${ this.getAttribute("id") }__logo`);
this.shadowRoot.append(logoElement);
}
}
customElements.define('top-bar-element', TopBar);
And here's the HTML:
<top-bar-element id="top-bar"></top-bar-element>
Yet, when I check, I find <logo-element id="null__logo"></logo-element>
.
I suppose it is because the browser only sets the attribute after the creation of the element.
Is there any other explanation? Are there workarounds?