dimanche 19 septembre 2021

Javascript checked checkbox result?

I am practicing javascript code that looks like this,

Now I want to keep the first checked result when more than two checkboxes are selected.

plz give some feedback.

thanks

    const pdItem = document.querySelectorAll('.shopbox');

    document.querySelector('.item-container').addEventListener('click', (event) => {
        const filterClass = event.target.dataset['name'];
        pdItem.forEach(elem => {
            if ((filterClass !== null) && !elem.classList.contains(filterClass)) {
                elem.classList.add('hide');
            } else {
                elem.classList.remove('hide')
            }
        })
    });



Aucun commentaire:

Enregistrer un commentaire