elpideus
elpideus

Reputation: 125

Can I select again from element variable in Cheerio?

I just started using Cheerio. How can I select again from a loop element?

const championBox = $('div.css-1s4j24f>div');
championBox.each(async function(index, element) {
    console.log(
    // I want to get element>div.something>span.somethingelse
    )
})

Thanks in advance.

Upvotes: 1

Views: 196

Answers (2)

lusc
lusc

Reputation: 1406

You can use .find, it is the cheerio equivalent of .querySelectorAll.
Using > at the start of the string makes it behave like element > div.something ...

const championBox = $('div.css-1s4j24f>div');
championBox.each(async function(index, element) {
    console.log(
        $(element).find('>div.something>span.somethingelse')
    )
})

Upvotes: 1

Achraf
Achraf

Reputation: 109

const championBox = $('div.css-1s4j24f>div');
championBox.each(async function(index, element) {
    const result = $(element).find('div.something>span.somethingelse');
})

Upvotes: 1

Related Questions