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
If _toShow is a class, you had to select it like so:
It looks like your problem was that you were presenting _toShow as a literal string instead of a variable. Try breaking it out with plus signs in the queerySelectorAll func.
Another possible issue is that you weren’t resetting the styles of previous cards before setting styles on the selected one(s). I used the colors red and black to demonstrate. Depending on what you’re doing, this might not be applicable.