Testing Shadow DOM
<foo-component id="fooShadowRoot"></foo-component>
<template id="fooTemplate">
<div id="shadowLocalTarget">
Local Target in Shadow DOM
</div>
</template>document.addEventListener( "DOMContentLoaded", () => {
function registerCustomElement( elName, templateId ) {
globalThis.customElements.define( elName, class extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: "open" });
this.shadowRoot.appendChild( document.getElementById( templateId ).content );
}
});
}
registerCustomElement( "foo-component", "fooTemplate" );
});




Last updated