const imgs = document.querySelectorAll(".img"); // You can't simply use imgs.forEach as it is not exactly an array. To fix that, first convert it to an array and then iterate. [...imgs].forEach(img => { console.log(img); });