How to get child element by id ?
See original GitHub issueHow to get a specific child element by id. In the following example I would like to get the canvas
child element in order to draw something on it:
class MyElement extends LitElement {
_render() {
return html`
<canvas id="draw"></canvas>
`;
}
}
With Polymer elements I used to get the child element with this.$.draw
but it’s not working with LitElement. What is the workaround ?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:14 (3 by maintainers)
Top Results From Across the Web
Get Child Element by ID using JavaScript | bobbyhadz
To get a child element by id, use the `document.querySelector()` method to get the parent element and call the `querySelector` method on the...
Read more >javascript get child by id - Stack Overflow
As mentioned, IDs are supposed to be unique within a document, so it's easiest to just use document.getElementById("child") . Share.
Read more >Getting Child Elements of a Node in JavaScript
First, select the #menu element by using the getElementById() method. · Second, get the first child element by using the firstElementChild property.
Read more >HTML DOM Element children Property - W3Schools
Get a collection of the <body> element's children: ... The children property returns a collection of an element's child elements. The children property ......
Read more >Get child element in JavaScript HTML DOM - CodeSpeedy
In JavaScript HTML DOM, we can easily get the child element of a parent element using the childNodes property. In the above HTML,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
this.shadowRoot.getElementById('draw')
should workI think, generally, it’s better to use
this._root
as it accounts forshadydom
, as well asshadowdom
, also you can usethis.renderComplete.then
in your constructor to wait until the first render is complete.