0

I have this code below for my html

<template>
    //do stuff
    <template if:true={openModal}>
        <ul>
           //add dynamic list here
         </ul>
    </template>
</template>

My Javascript I use the renderedCallback() to dynamically append a list to the ul.

 renderedCallback(){
    if(!this.hasRendered && this.data){
        //create a string of li elements called 'val' here

       //append the 'val' to the ul element
       this.template.querySelector('ul').innerHTML = val;  //returns null;
    }
}

When I go to run this the querySelect is returning null even though that ul exists in the html and the dom is loaded since renderedCallback is used for this purpose. Can someone please tell me why this is not working?

1
  • Is openModal value true in renderedCallback? Commented May 6, 2022 at 6:29

1 Answer 1

1

There's nothing wrong with this in LWC directly. I even wrote a demo. However, inside Salesforce, you need to remember to use lwc:dom="manual". Note that directly manipulating innerHTML is not recommended. You should consider rendering the data with a template directly, if possible.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.