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 :
JavaScript
x
4
1
$(".classParent").each((i, el) => {
2
prop[i] = $(el).find(".class1 .class2").attr("style")
3
})
4
It returns me only one div.class2 from every .class1.
I want results like this:
JavaScript
1
7
1
[
2
{}, // 1st object which contains all style properties of .class2 of 1st .class1
3
{}, // 2nd object which contains all style properties of .class2 of 2nd .class1
4
{}, // 3rd object which contains all style properties of .class2 of 3rd .class1
5
6
]
7
And this is how my objects would look like:
JavaScript
1
7
1
{
2
"style attribute value",
3
"style attribute value",
4
"style attribute value",
5
6
}
7
Advertisement
Answer
You can use the toArray
function:
JavaScript
1
8
1
$(".classParent").each((i, el) => {
2
prop[i] = $(el)
3
.find(".class1 .class2")
4
.toArray()
5
.map($)
6
.map(d => d.attr("style"));
7
}
8