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

64
Visualizações
Using jQuery contains with array

Instead of writing this a bunch of times (which works):

$('.this--class:contains("Some text")').parent().clone().appendTo($(".other--class"));

$('.this--class:contains("Other text")').parent().clone().appendTo($(".other--class"));

$('.this--class:contains("More text")').parent().clone().appendTo($(".other--class"));

If trying to figure out if I can put the text items into an array and then loop through them using jQuery and then have it clone to the .other--class.

My example:

var items = [
        "Some text",
        "Other text",
        "More text"
      ];
      $.each(items, function (index, value) {
        $(".this--class:contains(value)").parent().clone().appendTo($(".other--class"));
      }

If I do a console.log(value); I can see it kick out the correct items in the console. I'm just not sure of the correct way to have :contains() recognize that text, or if I need to go about this differently. Overall just looking of an easier way to not have to write the same thing over and over.

about 4 years ago · Santiago Trujillo
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