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

145
Views
How to parse multiple div with same class name in a div in cheerio?

I have "n" number of classes with className: "classparent" In which I have "n" number of classes with className: "class1" which consists of "n" number of div's with className: "class2"

How can I parse each and every of these div.class2 and get their style property in cheerio ???

Currently I am doing this :

$(".classParent").each((i, el) => {
    prop[i] = $(el).find(".class1 .class2").attr("style")
})

It returns me only one div.class2 from every .class1.

I want results like this:

[
 {}, // 1st object which contains all style properties of .class2 of 1st .class1
 {}, // 2nd object which contains all style properties of .class2 of 2nd .class1
 {}, // 3rd object which contains all style properties of .class2 of 3rd .class1
 ...
]

And this is how my objects would look like:

{
 "style attribute value",
 "style attribute value",
 "style attribute value",
 ......
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use the toArray function:

$(".classParent").each((i, el) => {
    prop[i] = $(el)
        .find(".class1 .class2")
        .toArray()
        .map($)
        .map(d => d.attr("style"));
}
about 4 years ago · Juan Pablo Isaza Report
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!