I am making a browser extension and I want to modify some things on the page but I run into this problem.
Then event listener gets triggered 'plug-stats' is not yet created by script on the page I can't control and gives me undefined so I tried to read it a little bit later but then I run into a problem.
First console log will give me a target as expected but I can't do anything with it yet because 'plug-stats' were not yet created. Second console log gives me null.
Why is this happening and any ideas on how can I fix it?
let perk = document.querySelectorAll('.ItemPerksList-m_plug-O8be3')
perk.forEach(element => {
element.addEventListener('click', add_perk_description);
});
function add_perk_description(event){
console.log(event.currentTarget)
setTimeout(() => {
console.log(event.currentTarget)
let html = event.currentTarget.getElementsByClassName('plug-stats')[0]
}, 1)
}