Is there is a way to get a child lit-element (by its name) in the host?
I only know how to access them using id and this.shadowRoot.getElementById()
import { LitElement, html } from 'lit-element';
import './child-element.js';
class ParentElement extends LitElement {
render() {
return html`<child-element someattribute="somevalue"></child-element>`;
}
}
Is there is a way to get a child lit-element (by its name) in the host?
I only know how to access them using id and this.shadowRoot.getElementById()
import { LitElement, html } from 'lit-element';
import './child-element.js';
class ParentElement extends LitElement {
render() {
return html`<child-element someattribute="somevalue"></child-element>`;
}
}
Share
Improve this question
edited Apr 2, 2019 at 3:53
Nomad
asked Apr 1, 2019 at 18:48
NomadNomad
4296 silver badges16 bronze badges
1 Answer
Reset to default 7Turns out it was simply calling shadowRoot.querySelector("element-name")
:
...
class ParentElement extends LitElement {
render() {
return html`<child-element someattribute="somevalue"></child-element>`;
}
aMethod() {
let childElement = this.shadowRoot.querySelector("child-element");
}
}
...