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

138
Visualizações
Is it (efficiently) possible to get a list of elements in JavaScript that have a certain CSS property set?

I know we can use document.querySelectorAll(yada yada yada) to get a list of elements that match any CSS selector, but is it possible to come at the problem from another angle, and match any element with a certain CSS property?

I've written a function to shrink any flex-wrap containers to the correct size, without the ugly gap on the right hand side that current CSS means we're always stuck with. (Aside: is there something in an upcoming spec to fix this issue?)

I'd like it to run automatically on any flex-wrap containers on my site.

I don't want to add a class="flex-wrap" to each element. I know tailwind et al are all about this type of classes these days, but I'm old school. I believe in separation of design/content and that class/IDs should be semantic, not stylistic.

But for this "problem", the only solutions I can see are:

  1. manually add IDs/classes of elements which I know need the fix in my JavaScript
  2. add a class that querySelectorAll can latch on to
  3. loop through every element calling getComputedStyles() to check for this CSS property. I've not tried that, as some of my pages have many thousands of DOM elements, and I know it's a terrible idea.

Is there a better 4th option that I've not considered?

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