Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

192
Vistas
"ForEach is not a function" Can't make console.log picked filter

In my script below you can see what i have made. Idea is to make this filter products on page by adding values to array and check class later.

// FILTERS 
var wybranyKolor = [];
var wybranyRozmiar = [];

function selectFilter(){
    document.querySelectorAll(".grupa").forEach(group => {

        var colorFilter = group.querySelector('.button-group-color').querySelectorAll('.button')
        var sizeFilter = group.querySelector('.button-group-size').querySelectorAll('.button')

        // KOLORY
        colorFilter.forEach((button) => {
            button.addEventListener("click", (e) =>{
                colorFilter.forEach((thisColor) => {
                    thisColor.classList.remove("sg_active");
                    wybranyKolor.pop(filtr);
                })
                button.classList.add("sg_active");
                var filtr = button.getAttribute('data-filter');
                wybranyKolor.push(filtr);
                showProducts();
                console.log(wybranyKolor);
            });
        });

        // ROZMIAR
        sizeFilter.forEach((button) => {
            button.addEventListener("click", (e) =>{
                sizeFilter.forEach((thisSize) => {
                    thisSize.classList.remove("sg_active");
                    wybranyRozmiar.pop(filtr);
                })
                button.classList.add("sg_active");
                var filtr = button.getAttribute('data-filter');
                wybranyRozmiar.push(filtr);
                showProducts();
                console.log(wybranyRozmiar);
            });
        });
    });
}

Here i get stuck, any ideas how to console.log values from array same as class in divs ?

Uncaught TypeError: boxPro.forEach is not a function

function showProducts(){
    document.querySelectorAll('.grid').forEach(gridDiv => {
        var boxPro = gridDiv.querySelector('.box_pro');

        boxPro.forEach((elementDiv) => {
            if(elementDiv.classList.contains(wybranyKolor)){
                console.log('MAM ' + wybranyKolor);
            }
        });
    });
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You're trying to call an array prototype method on a primitive value. The querySelector() only selects the first element it finds, so you're not able to iterate over it. If you really need the forEach method, you may be able to do a querySelectorAll() and have it return an array with 1 element.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda