Having some dynamic HTML code in my JS, I'm hoping to assign an ID to a particular tag:
content: `
<p id="openKeyboard">
If the click happens, I want to trigger an event.
</p>
`
However, upon checking the console, this message pops up: https://i.sstatic.net/dbBmC.png
const el = document.getElementById("openKeyboard");
el.addEventListener("click", this.modifyText, false);
It seems that placing id="openKeyboard" on an element within the DOM works fine. But when dealing with HTML inside the JS file, using getElementById and addEventListener poses a challenge. Any ideas on how to make it work without being part of the DOM?