Given the following sample code:
import { LitElement, html, css } from 'lit-element';
class ItemsDisplay extends LitElement {
static get styles() {...}
static get properties {...}
constructor () {
super();
...
}
render {
return html`
${this.items.map((item, index, array) => html`
<div class="name">
...
</div>
`)}
`;
}
}
What is the appropriate way to select all nodes with class "name"?
I have tried the following ways, but failed; all times nodesList
was undefined
:
- Inside
constructor
:
this.nodesList = this.shadowRoot.querySelectorAll(".name");
- Using:
firstUpdated(changedProperties) {
return this.nodesList = this.shadowRoot.querySelectorAll(".name");
}
- Inside a custom function:
getNodesList() {
let nodesList = this.shadowRoot.querySelectorAll(".name");
...
}
I have also tried with:
connectedCallback() {
super.connectedCallback();
return this.nodesList = this.shadowRoot.querySelectorAll(".name");
}
Looking forward reading the solution.
Tia