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

128
Visualizações
Apply .not() filter using js

I need to apply not(.pseudo-element) filter using js but not sure how to add it so far i've manage to extract #app from the DOM using:

const app = document.getElementById('app')
    
app.style.filter = 'brightness(0.5)'

Now my goal is to apply this brightness to all childs with exception for one, how to achieve it using js

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

0

You could use shotgun02's answer or something like this:

const elements = [...app.querySelectorAll('*:not(.pseudo-element)')];

elements.forEach((element) => {
  element.style.filter = 'brightness(0.5)';
});

In the example above I'm using spread syntax ([...app.querySelectorAll()]) because I personally prefer to work with Objects instead of NodeList but that's a personnal preference.

Another approach would be to use the .classList() method :

const elements = [...app.querySelectorAll('*')];

elements.forEach((element) => {
  if (!element.classList.contains('pseudo-element')) {
    element.style.filter = 'brightness(0.5)';
  }
});

Keep in mind that the best approach is probably to do the same thing with CSS if you don't really need JS for that.

* {
  filter: brightness(0.5);
}

.pseudo-element {
  filter: none;
}

about 4 years ago · Juan Pablo Isaza Relatório

0

You can try the :not() selector as shown below which will return all child elements from app excluding elements having .pseudo-element class.

app.querySelectorAll('*:not([class="pseudo-element"])');

Another way to write the same is as belows:-

app.querySelectorAll('*:not(.pseudo-element)');

The :not(selector) selector also accepts commas

app.querySelectorAll('*:not(.pseudo-element,.pseudo-element-2)');
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