Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

65
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda