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
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");
}
}
...
本文标签: javascriptHow to query children of Litelement shadow root using tag nameStack Overflow
版权声明:本文标题:javascript - How to query children of Lit-element shadow root using tag name - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742355475a2459319.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论