How can I access my custom element render-root-test
to run a query such as getElementById
?
Using the LitElement library, it’s recommended to use the shadowRoot
to access custom elements. However, I’m overriding the shadowRoot
by using the createRenderRoot()
method, so this won’t work. How do I access my custom element render-root-test
to run a query such as getElementById
?
import { LitElement, html }
from 'https://unpkg.com/lit-element/lit-element.js?module';
class RenderRootTest extends LitElement {
constructor() {
super();
}
render () {
const renderRoot = this.shadowRoot; //Won't work, because I'm overriding the shadowroot
return html`
<div>Rendered</div>
${renderRoot ?
html`<div>Render root found</div>` :
html``
}
`;
}
createRenderRoot() {
return this;
}
}
customElements.define('render-root-test', RenderRootTest);