Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

156
Visualizações
Is there a way to show an element if it has all of the classes matched from an array that is consistently having variables pushed in and out of it?

I'm creating a sorting program for DnD spells that sorts all 318 spells into 83 different categories. I have multiple arrays storing all of the information, and I know how to check if an element has a class from an array.

However, I want to sort the spells based on multiple tags at once, for example, selecting the Druid tag and the Level 9 tag would show only spells with those tags, but then deselecting Level 9 would show all of the Druid spells. The amount of tags chosen can go up or down consistently, and what I'm essentially looking for is something that can take all of the tags that are selected (pushed into an array) and check if all of those tags are classes in each div element, showing only the elements that contain all of the classes in the tag selection array. As it stands now, I've only been able to achieve it checking for the first tag I select, and then everything goes blank after I select a second class.

Here is what I've tried:

var selections = [];

function showCards(e) {
    $(".spellCards > img").hide();
    selections.push(classes[e]);
    
    for(var i = 0; i < 318; i++) {


    // I'm putting all of my attempts here at once, they weren't run at the same time.
        if(spellCard[i].classList.contains(selections)) {
            $(spellCard[i]).show();
        }

        if(spellCard[i].classList.matches(selections)) {
            $(spellCard[i]).show();
        )

        if(spellCard[i].classList.contains.every(selection)) { // First tag works
            $(spellCard[i]).show();
        )

        if(selection.every(c=>spellCard[i].classList.contains(c))) {
            $(spellCard[i]).show();
        )

        if(spellCard[i].classList.contains(classes[e])) {
            $(spellCard[i]).show();
        }  
    }
}
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda