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

148
Visualizações
How do I filter an array by display type if display type is set by bootstrap?

I am trying to filter an array of portfolio cards so that I can see which items are displayed or not.

let pfCard = document.getElementsByClassName("PortfolioCard")

const visibleCards = [...document.getElementsByClassName("PortfolioCard")].filter(x => x.style.display != "none");
console.log(visibleCards.length);

The displayed cards are having the display set to none by a bootstrap class when the media query is met. The code I have been trying to run still grabs all the elements in the array no matter the display type. There are 8 elements in the array and 2 are set to display: none; currently.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Because the element's display property is set by the CSS file, you'll need to get the computed style using window.getComputedStyle:

let pfCard = document.getElementsByClassName("PortfolioCard")

const visibleCards = [...document.getElementsByClassName("PortfolioCard")].filter((x) => {
  return window.getComputedStyle(x).display != "none"
});
console.log(visibleCards.length);
.PortfolioCard {
  width: 100px;
  height: 100px;
  background: red;
  margin: 10px;
}

.PortfolioCard:nth-child(3) {
  display: none;
}
<div class="PortfolioCard"></div>
<div class="PortfolioCard"></div>
<div class="PortfolioCard"></div>

about 4 years ago · Juan Pablo Isaza Relatório
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