getElementById is not a function

Hi,
I try to add an eventlistener to an button with getElementById() like shown here: https://developer.adobe.com/indesign/uxp/resources/recipes/html-events/

But only the inline version works. If I add a my listener like:

const addHeaderImgBtn = document.getElementById("headerImg"); 
addHeaderImgBtn.addEventListener("click", showHeaderimg);

with this I get the error getElementById is not a function. Have I to import first a class or something else?

Best regards

What’s your actual document? I’m pretty sure it’s UXP doc, and not HTML. Or you could try window.document maybe. Not sure though

I found out what I did wrong. I override the document with my own constant for app.activeDocument. window.document d oalso work, thanks!