skip to Main Content

I try to call a variable within the querySelectorAll() Method. It doesn’t work out.

function _hide() {
        
        //Returns as string which corresponds exactly to the Class I want to store

        let _toShow = "." + document.getElementById("fb-select").value;
        
        //Should store a Nodelist wich contains evrything except the class to show

        let card = document.querySelectorAll('.card:not(_toShow)')

        //Hides the elements in the Nodelist
        card.forEach((card) => {
            card.style.scale = "0";
            card.style.opacity = "0";
        });
    }

The Usecase is to hide all Elements wich have not a specific Class.
Thanks for Advice.

2

Answers


  1. If _toShow is a class, you had to select it like so:

    let card = document.querySelectorAll('.card:not(._toShow)')
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search