I'm using lwc:dom="manual" and querySelector to capture and display the text content but it does not work.
HTML code
<h2 class="slds-truncate" title={record.Name}>
<a href="#" data-id={record.Id}>
<div class="first-el" lwc:dom="manual"></div>
</a>
</h2>
JS code
renderedCallback() {
let firstEl = document.querySelector(".first-el");
console.log('First El',firstEl);
firstEl.innerHTML = '<span class="slds-truncate" data-id={record.Id}>First Element</span>';
}
or
connectedCallback() {
let firstEl = document.querySelector(".first-el");
console.log('First El',firstEl);
firstEl.innerHTML = '<span class="slds-truncate" data-id={record.Id}>First Element</span>';
}
Because it needs to be rendered when the page load so I tried to do it within the connectedCallback
and renderedCallback
but the result returned the same. And the record
is a public property (@api record) that is passed from Parent component. I'm not sure if this effect the error.
Thank you so much!