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

219
Visualizações
How do you check if a css class is present on an element?

i have this piece of code where i wanna check if a css class is present,if so then want to remove that specific class.

var el = document.querySelector('.main-content');

const promo = 'projectPromoActivateMobile';
const transaction = 'projectTransactionActivate';
const newsletter = 'projectNewsletterActivate';
const landingPage = 'projectLandingPageActivate ';

const classLists = [promo,transaction,newsletter,landingPage]


let check = el.classList.contains(promo || transaction ||newsletter || landingPage);

console.log(check);

this does the work and check but can not seem to get the name of the class,which needs to be removed.

how would you check if that specific css class is present in the element?

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

0

promo || transaction || newsletter || landingPage will resolve to promo, since all values are strings of non-zero length (therefore truthy). All following values will be ignored.

Therefore, this code :

let check = el.classList.contains(promo || transaction ||newsletter || landingPage);

is exactly the same as this :

let check = el.classList.contains(promo);

Instead, you want to use something like this:

const classLists = ["promo","transaction","newsletter","landingPage"];
let check = el.classList.some(class => classLists.includes(class));
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