Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

200
Views
"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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!