Seeking assistance in iterating a NodeList object using javascript, and implementing a click event for each item :
document.addEventListener("DOMContentLoaded", async () => {
try {
posts.map(post => {
container.innerHTML += outPutHtml(post); // user-interaction elements are created with ajax request
} catch (e) {
console.error(e);
} finally {
highlight.highlightAll();
});
const elements = document.querySelectorAll(".user-interaction");
console.log(elements); // NodeList []length: 0[[Prototype]]: NodeList
console.log(typeof elements); // object
elements.forEach(function(element) {
element.addEventListener("click", function() {
console.log('ok');
});
});
The click event on element doesn’t seem to work!
In need of a solution to fix this issue.