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

145
Visualizações
jQuery Applying class to list of THs via their text()

I have some ths that I know the text value of. I want to apply a class to a certain list of these ths.

What I have works like a charm, I just want to see if there's a better way to write it.

   //Custom extended jQuery psuedo function to check if text() of elem is exactly some string (ensures it doesn't overwrite existing fn)
//Ref: https://stackoverflow.com/a/18462522/2402616
        $.expr[':'].textEquals = $.expr[':'].textEquals ||
        $.expr.createPseudo(function(arg) {
            return function( elem ) {
                return $(elem).text() === arg;
            };
        });

     const textsOfThsToAddClassTo = ['foo','bar','fizz',buzz'];

    //Here's where my question really is
    textsOfThsToAddClassTo.forEach(text => {
        $(`th:textEquals('${text }')`).addClass('my-class');
    });

I'm just wondering if there's a better way to write that forEach part. Like, if I can use a selector to only contain what's in the array. Thanks!

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