Kevin Powell - CommunityKP-C
Kevin Powell - Community4y ago
40 replies
Dovah

Help with simple IF statement!

for(let i=0;i<filtersDiv.length;i++) {
        let selectedFilter;
        let filterOut = "";
        let clickCounter = 0;
        filtersDiv[i].addEventListener('click', () => {
            filterBox.classList.add('active-flex');
            container.style.top = "-90px";
            selectedFilter = filtersDiv[i].innerHTML;
            clickCounter++
            filterOut = `
            <div class="selected-filter-unit">
                <p class="selected-filter">${selectedFilter}</p>
                <button class="remove-filter"><img src="images/icon-remove.svg" alt="Remove icon"></button>
            </div>
            `;
            selectedFilters.innerHTML = selectedFilters.innerHTML + filterOut;
            removeFilterScript();
            // cardFilter();
        })
    }

is part of the code that should contains IF that I'm having problem with

selectedFilters.innerHTML = selectedFilters.innerHTML + filterOut;

line of code that should have IF condition that should state: IF "selectedFilters.innerHTML" already has a div inside, with the same value of ${selectedFilter}, it should not add another div. So, no 2 same filters should be active at the same time.

Please help. 😦
Was this page helpful?