How to write callback for newly added element in DOM upon click action in javascript?


I have a button which adds new element to DOM. Now I want to write event listner for click on this new Element. But not able to do so because when page loads this element will not be in DOM. The code I have tried so far is

    const initButton = document.querySelector(".wS .amr .amn .ams");
    initButton.click() // this will add new element in DOM which will be async action

    // now I want to perform following on newly added element
    
    document.querySelector(".fX.aXjCH").setAttribute("style", "display:block");
    document.querySelector(".aB.gQ.pE").click();

I need some callback mechanism so that I can execute the later code once the DOM is updated with new component. How can I achieve this? how can I make assure the DOM is updated? or is there any way I can write callback for the first click()?