Notes
<template>
<div>First<slot name="task1">Task 1</slot></div>
<div>Second<slot name="task2">Task 2</slot></div>
</template>
To access elements rendered by a component, use;
this.template.querySelector();
this.template.querySelectorAll();
import { LightningElement } from 'lwc';
export default class Example extends LightningElement {
renderedCallback() {
this.template.querySelector('div'); // <div>First</div>
this.template.querySelector('span'); // null
this.template.querySelectorAll('div'); // [<div>First</div>, <div>Second</div>]
}
}
The order of elements is not guaranteed.
Elements not rendered to the DOM aren’t returned in the querySelector result.
this.template.querySelector('span');
Don’t use ID selectors with querySelector. The IDs that you define in HTML templates may be transformed into globally unique values when the template is rendered. If you use an ID selector in JavaScript, it won’t match the transformed ID.
Video
Video does not exists.