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

157
Visualizações
Is there a way to create an array of an element that contains a specific CSS style?

I'm trying to capture the elements that do not contain a display type of none.

let pfCard = document.getElementsByClassName("PortfolioCard").style.display = 'block';

This doesn't seem to be working as I believe it is attempting to modify the style type instead of retrieve it.

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

0

You can do this by getting all your elements by class name and then using filter on that list.

 const blockElements = [...document.getElementsByClassName("PortfolioCard")].filter(x => x.style.display == "block");
 console.log(blockElements.length);
<div class="PortfolioCard" style="display:block">block</div>
<div class="PortfolioCard">not block</div>
<div class="PortfolioCard" style="display:block">block</div>

about 4 years ago · Juan Pablo Isaza Relatório

0

You'd probably have to querySelectorAll(".PortfolioCard") to get an array of them, then .filter() the array looking for style.display != 'none'.

A nicer solution would be if you separate your display: none property into a small utility class like: .hide-portfolio { display: none; }, and hide them that way. Then you can search for them with querySelectorAll(".PortfolioCard:not(.hide-portfolio)");

about 4 years ago · Juan Pablo Isaza Relatório

0

Maybe this one?

console.log([...document.getElementsByClassName("PortfolioCard")].filter(item=> window.getComputedStyle(item).getPropertyValue('display') != "block"))
<div class='PortfolioCard' style='display:block'></div>
<div class="PortfolioCard" style="display:block"></div>
<div class="PortfolioCard" style='display:none'></div>

Or usearray.forEach:

let arr= [];
[...document.getElementsByClassName("PortfolioCard")].forEach(item=>{
if(window.getComputedStyle(item).getPropertyValue('display') != "block") 
arr.push(item)
})
console.log(arr)
<div class='PortfolioCard' style='display:block'></div>
<div class="PortfolioCard" style="display:block"></div>
<div class="PortfolioCard" style='display:none'></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