jeudi 29 août 2019

Adding an if statement to the for loop code to hide the covers

What I want to do is hide the covers after they are clicked using an if statement placed in the for loop code. If that’s where it would go.

Preventing this from occurring. Image

I attempted to do that here but wasn't able to figure it out.

What am I doing wrong in trying to figure this out?

https://jsfiddle.net/8mg0v6eL/2/

(function manageCover() {
    "use strict";

    function hide(el) {
        el.classList.add("hide");
    }

    /*function coverClickHandler(evt) {
        const cover = evt.currentTarget;
        hide(cover);
    }*/

    function addCoverListener(evt) {
        const cover = evt.target;

        const coversSelector = ".jacket-left, .jacket-middle, .jacket-right";
        const covers = document.querySelectorAll(coversSelector);

        for (let i = 0; i < covers.length; i += 1) {
            /*covers[i].addEventListener("click", coverClickHandler);*/
            if (covers[i] !== evt.target) covers[i].hide(cover);
        }
    }

}());

Aucun commentaire:

Enregistrer un commentaire