admin管理员组

文章数量:1336311

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
Add a ment  | 

1 Answer 1

Reset to default 7

Turns 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");
  }
}
...

本文标签: javascriptHow to query children of Litelement shadow root using tag nameStack Overflow