Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

194
Visualizações
"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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda