Within my DOM, I have dynamically created spans that all have the class "foo".
Utilizing TypeScript, I aim to attach an onClick event to each of these spans post-creation.
Here is my current approach:
var foos = document.body.querySelectorAll(".foo");
foos.forEach(function (item) {
item.addEventListener("click", () => {
console.log(item);
});
});
However, I am facing an issue with running forEach on a NodeListOf.
Using foos = Array.from(foos) does not resolve the problem as it results in: 'from' doesn't exist on type 'ArrayConstructor'.