javascript - How to query children of Lit-element shadow root using tag name - Stack Overflow

Is there is a way to get a child lit-element (by its name) in the host?I only know how to access them u

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742355475a4428342.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信