Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

63
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!